conf.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. Serve serve
  22. DB db
  23. Udp udp
  24. Nsq nsq
  25. Mail mail
  26. Log log
  27. }
  28. type serve struct {
  29. MsgAddr string
  30. FieldS []string
  31. }
  32. type udp struct {
  33. LocPort string
  34. Next udpNext
  35. Project udpNext
  36. Tidb udpNext
  37. Tidb1 udpNext
  38. Tidb2 udpNext
  39. }
  40. type nsq struct {
  41. Addr string
  42. Topic string
  43. Channel string
  44. Concurrent int
  45. }
  46. type udpNext struct {
  47. Addr string
  48. Port int
  49. Stype string
  50. }
  51. type mail struct {
  52. Send bool
  53. To string
  54. Api string
  55. }
  56. // Log Config
  57. type log struct {
  58. LogPath string
  59. MaxSize int
  60. Compress bool
  61. MaxAge int
  62. MaxBackups int
  63. LogLevel string
  64. Format string
  65. }
  66. type db struct {
  67. MongoB mgo
  68. MongoE mgo
  69. MongoQ mgo
  70. MongoP mgo
  71. Redis redis
  72. Es es
  73. }
  74. type mgo struct {
  75. Addr string
  76. Dbname string
  77. Coll string
  78. Coll1 string
  79. Size int
  80. User string
  81. Password string
  82. }
  83. type redis struct {
  84. Addr string
  85. DbIndex int
  86. }
  87. type es struct {
  88. Addr string
  89. User string
  90. Password string
  91. }
  92. type duration struct {
  93. time.Duration
  94. }
  95. // UnmarshalText parse 10s to time.Time
  96. func (d *duration) UnmarshalText(text []byte) error {
  97. var err error
  98. d.Duration, err = time.ParseDuration(string(text))
  99. return err
  100. }