conf.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. Pici int64
  29. Thread int
  30. TagRule string
  31. JyHref string
  32. }
  33. type udp struct {
  34. LocPort string
  35. }
  36. type es struct {
  37. Addr string
  38. Size int
  39. IndexP string
  40. MinSdMh string
  41. }
  42. type mail struct {
  43. Send bool
  44. To string
  45. Api string
  46. }
  47. // Log Config
  48. type log struct {
  49. LogPath string
  50. MaxSize int
  51. Compress bool
  52. MaxAge int
  53. MaxBackups int
  54. LogLevel string
  55. Format string
  56. }
  57. type db struct {
  58. MongoB mgo
  59. MongoP mgo
  60. Mysql mysql
  61. Es es
  62. Redis redis
  63. }
  64. type mgo struct {
  65. Addr string
  66. Dbname string
  67. ProposedColl string
  68. CombColl string
  69. ProjectColl string
  70. Size int
  71. User string
  72. Password string
  73. }
  74. type redis struct {
  75. Addr string
  76. Pcode string
  77. Db int
  78. }
  79. type mysql struct {
  80. Addr string
  81. DbnameBasic string
  82. DbnameMedical string
  83. Size int
  84. User string
  85. Password string
  86. }
  87. type duration struct {
  88. time.Duration
  89. }
  90. // UnmarshalText parse 10s to time.Time
  91. func (d *duration) UnmarshalText(text []byte) error {
  92. var err error
  93. d.Duration, err = time.ParseDuration(string(text))
  94. return err
  95. }