conf.go 1.2 KB

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