conf.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. Mail mail
  25. Log log
  26. }
  27. type serve struct {
  28. FileWarn int
  29. PyWarn int
  30. }
  31. type udp struct {
  32. LocPort string
  33. Next udpNext
  34. }
  35. type udpNext struct {
  36. Addr string
  37. Port int
  38. Stype string
  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. MongoB mgo
  57. Es es
  58. }
  59. type mgo struct {
  60. Addr string
  61. Dbname string
  62. Size int
  63. User string
  64. Password string
  65. }
  66. type es struct {
  67. Addr string
  68. Size int
  69. IndexS string
  70. TypeS string
  71. }
  72. type duration struct {
  73. time.Duration
  74. }
  75. // UnmarshalText parse 10s to time.Time
  76. func (d *duration) UnmarshalText(text []byte) error {
  77. var err error
  78. d.Duration, err = time.ParseDuration(string(text))
  79. return err
  80. }