conf.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. Udp udp
  23. Mail mail
  24. Log log
  25. }
  26. type udp struct {
  27. LocPort string
  28. JyAddr string
  29. JyPort int
  30. }
  31. type udpNext struct {
  32. Addr string
  33. Port int
  34. Stype string
  35. }
  36. type mail struct {
  37. Send bool
  38. To string
  39. Api string
  40. }
  41. // Log Config
  42. type log struct {
  43. LogPath string
  44. MaxSize int
  45. Compress bool
  46. MaxAge int
  47. MaxBackups int
  48. LogLevel string
  49. Format string
  50. }
  51. type db struct {
  52. MongoB mgo
  53. MongoP mgo
  54. MongoQ mgo
  55. Es es
  56. Oss oss
  57. }
  58. //oss oss 阿里云配置
  59. type oss struct {
  60. Endpoint string
  61. AccessKey string
  62. AccessSecret string
  63. BucketName string
  64. }
  65. type mgo struct {
  66. Addr string
  67. Dbname string
  68. Coll string
  69. Size int
  70. User string
  71. Password string
  72. }
  73. type es struct {
  74. Addr string
  75. AddrP string
  76. Size int
  77. Username string
  78. Password string
  79. IndexB string
  80. TypeB string
  81. IndexP string
  82. TypeP string
  83. IndexWinner string
  84. TypeWinner string
  85. IndexBuyer string
  86. TypeBuyer string
  87. FieldEs map[string]interface{}
  88. FieldPurchasingList map[string]interface{}
  89. FieldProcurementList map[string]interface{}
  90. FieldWinnerOrder map[string]interface{}
  91. DetailFilter []string
  92. }
  93. type duration struct {
  94. time.Duration
  95. }
  96. // UnmarshalText parse 10s to time.Time
  97. func (d *duration) UnmarshalText(text []byte) error {
  98. var err error
  99. d.Duration, err = time.ParseDuration(string(text))
  100. return err
  101. }