conf.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. DB Db
  22. Log Log
  23. }
  24. // Log Config
  25. type Log struct {
  26. LogPath string
  27. MaxSize int
  28. Compress bool
  29. MaxAge int
  30. MaxBackups int
  31. LogLevel string
  32. Format string
  33. }
  34. type Db struct {
  35. Mongo mgo
  36. Mongo1 mgo
  37. Mongo2 mgo
  38. Mysql mysql
  39. Es es
  40. }
  41. type mgo struct {
  42. Addr string
  43. Dbname string
  44. Size int
  45. User string
  46. Password string
  47. }
  48. type mysql struct {
  49. Addr string
  50. DbnameBasic string
  51. DbnameMedical string
  52. Size int
  53. User string
  54. Password string
  55. Drivename string
  56. Dsn string
  57. MaxIdle int
  58. MaxConn int
  59. MaxQueryTime duration
  60. }
  61. type es struct {
  62. Addr string
  63. Size int
  64. IndexM string
  65. TypeM string
  66. IndexS string
  67. TypeS string
  68. FieldM map[string]interface{}
  69. FieldS map[string]interface{}
  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. }