conf.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. Preset preset
  22. Es es
  23. Mysql mysql
  24. Mail mail
  25. Log log
  26. }
  27. type preset struct {
  28. Bidday int64
  29. Bidfield int
  30. Accuracy float64
  31. }
  32. type es struct {
  33. Addr string
  34. Size int
  35. Username string
  36. Password string
  37. Bidding string
  38. Project string
  39. Qyxy string
  40. Buyer string
  41. }
  42. type mysql struct {
  43. Addr string
  44. Dbname string
  45. Size int
  46. User string
  47. Password string
  48. }
  49. type mail struct {
  50. Send bool
  51. To string
  52. Api string
  53. }
  54. // Log Config
  55. type log struct {
  56. LogPath string
  57. MaxSize int
  58. Compress bool
  59. MaxAge int
  60. MaxBackups int
  61. LogLevel string
  62. Format string
  63. }
  64. type mgo struct {
  65. Addr string
  66. Dbname string
  67. Size int
  68. User string
  69. Password string
  70. }
  71. type duration struct {
  72. time.Duration
  73. }
  74. // UnmarshalText parse 10s to time.Time
  75. func (d *duration) UnmarshalText(text []byte) error {
  76. var err error
  77. d.Duration, err = time.ParseDuration(string(text))
  78. return err
  79. }