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