conf.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. DB db
  23. Mail mail
  24. Log log
  25. }
  26. type udp struct {
  27. LocPort string
  28. }
  29. type mail struct {
  30. Send bool
  31. To string
  32. Api string
  33. }
  34. // Log Config
  35. type log struct {
  36. LogPath string
  37. MaxSize int
  38. Compress bool
  39. MaxAge int
  40. MaxBackups int
  41. LogLevel string
  42. Format string
  43. }
  44. type db struct {
  45. Es es
  46. MongoB mgo
  47. MongoP mgo
  48. Mysql mysql
  49. }
  50. type mgo struct {
  51. Addr string
  52. Dbname string
  53. Size int
  54. User string
  55. Password string
  56. }
  57. type mysql struct {
  58. Addr string
  59. Dbname string
  60. Size int
  61. User string
  62. Password string
  63. }
  64. type es struct {
  65. Addr string
  66. Index 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. }