conf.go 1.5 KB

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