conf.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. Udp udp
  22. Serve serve
  23. DB db
  24. Mail mail
  25. Log log
  26. }
  27. type udp struct {
  28. LocPort string
  29. }
  30. type serve struct {
  31. Thread int
  32. ExField []string
  33. }
  34. type es struct {
  35. Addr string
  36. User string
  37. Password string
  38. Size int
  39. }
  40. type mail struct {
  41. Send bool
  42. To string
  43. Api string
  44. }
  45. // Log Config
  46. type log struct {
  47. LogPath string
  48. MaxSize int
  49. Compress bool
  50. MaxAge int
  51. MaxBackups int
  52. LogLevel string
  53. Format string
  54. }
  55. type db struct {
  56. Es es
  57. Mongo mgo
  58. Mongo1 mgo
  59. Mongo2 mgo
  60. Mysql mysql
  61. }
  62. type mgo struct {
  63. Addr string
  64. Dbname string
  65. Coll string
  66. Size int
  67. User string
  68. Password string
  69. }
  70. type mysql struct {
  71. Addr string
  72. Dbname string
  73. Size int
  74. User string
  75. Password string
  76. }
  77. type duration struct {
  78. time.Duration
  79. }
  80. // UnmarshalText parse 10s to time.Time
  81. func (d *duration) UnmarshalText(text []byte) error {
  82. var err error
  83. d.Duration, err = time.ParseDuration(string(text))
  84. return err
  85. }