conf.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. Mysql mysql
  41. Es es
  42. }
  43. type mgo struct {
  44. Addr string
  45. Dbname string
  46. Coll string
  47. Size int
  48. User string
  49. Password string
  50. }
  51. type mysql struct {
  52. Addr string
  53. DbnameBasic string
  54. DbnameMedical string
  55. Size int
  56. User string
  57. Password string
  58. Drivename string
  59. Dsn string
  60. MaxIdle int
  61. MaxConn int
  62. MaxQueryTime duration
  63. }
  64. type es struct {
  65. Addr string
  66. Size int
  67. IndexM string
  68. TypeM string
  69. IndexS string
  70. TypeS string
  71. FieldM map[string]interface{}
  72. FieldS map[string]interface{}
  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. }