conf.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. Thread 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. Mongo mgo
  57. Mongo1 mgo
  58. Es es
  59. }
  60. type mgo struct {
  61. Addr string
  62. Dbname string
  63. Coll string
  64. Size int
  65. User string
  66. Password string
  67. }
  68. type es struct {
  69. Addr string
  70. Size int
  71. IndexS string
  72. TypeS string
  73. }
  74. type duration struct {
  75. time.Duration
  76. }
  77. // UnmarshalText parse 10s to time.Time
  78. func (d *duration) UnmarshalText(text []byte) error {
  79. var err error
  80. d.Duration, err = time.ParseDuration(string(text))
  81. return err
  82. }