conf.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. MongoS mgo
  56. Es es
  57. Oss oss
  58. MysqlB mysql
  59. }
  60. type mysql struct {
  61. Addr string
  62. Dbname string
  63. Username string
  64. Password string
  65. }
  66. //oss oss 阿里云配置
  67. type oss struct {
  68. Endpoint string
  69. AccessKey string
  70. AccessSecret string
  71. BucketName string
  72. Filesize int
  73. }
  74. type mgo struct {
  75. Addr string
  76. Dbname string
  77. Coll string
  78. Size int
  79. User string
  80. Password string
  81. }
  82. type es struct {
  83. Addr string
  84. AddrP string
  85. Size int
  86. Username string
  87. Password string
  88. IndexB string
  89. TypeB string
  90. IndexP string
  91. TypeP string
  92. IndexWinner string
  93. TypeWinner string
  94. IndexBuyer string
  95. TypeBuyer string
  96. DetailFilter []string
  97. IndexTmp string
  98. //FieldEs map[string]interface{}
  99. //FieldPurchasingist map[string]interface{}
  100. //FieldProcurementList map[string]interface{}
  101. //FieldWinnerOrder map[string]interface{}
  102. //Package map[string]interface{}
  103. }
  104. type duration struct {
  105. time.Duration
  106. }
  107. // UnmarshalText parse 10s to time.Time
  108. func (d *duration) UnmarshalText(text []byte) error {
  109. var err error
  110. d.Duration, err = time.ParseDuration(string(text))
  111. return err
  112. }