conf.go 903 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package config
  2. import (
  3. "fmt"
  4. "os"
  5. "time"
  6. "github.com/BurntSushi/toml"
  7. )
  8. var (
  9. // Conf crocodile conf
  10. Conf *conf
  11. )
  12. // Init Config
  13. func Init(conf string) {
  14. _, err := toml.DecodeFile(conf, &Conf)
  15. if err != nil {
  16. fmt.Printf("Err %v", err)
  17. os.Exit(1)
  18. }
  19. }
  20. type conf struct {
  21. DB Db
  22. Log Log
  23. Buyer Buyer
  24. Winner Winner
  25. }
  26. // Log Config
  27. type Log struct {
  28. LogPath string
  29. MaxSize int
  30. Compress bool
  31. MaxAge int
  32. MaxBackups int
  33. LogLevel string
  34. Format string
  35. }
  36. // Buyer
  37. type Buyer struct {
  38. }
  39. // Winner
  40. type Winner struct {
  41. }
  42. type Db struct {
  43. Drivename string
  44. Dsn string
  45. MaxIdle int
  46. MaxConn int
  47. MaxQueryTime duration
  48. }
  49. type duration struct {
  50. time.Duration
  51. }
  52. // UnmarshalText parse 10s to time.Time
  53. func (d *duration) UnmarshalText(text []byte) error {
  54. var err error
  55. d.Duration, err = time.ParseDuration(string(text))
  56. return err
  57. }