conf.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. Thread int
  29. TagRule string
  30. ProColl 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. }
  41. type mail struct {
  42. Send bool
  43. To string
  44. Api string
  45. }
  46. // Log Config
  47. type log struct {
  48. LogPath string
  49. MaxSize int
  50. Compress bool
  51. MaxAge int
  52. MaxBackups int
  53. LogLevel string
  54. Format string
  55. }
  56. type db struct {
  57. MongoB mgo
  58. MongoP mgo
  59. Mysql mysql
  60. Es es
  61. }
  62. type mgo struct {
  63. Addr string
  64. Dbname string
  65. Coll string
  66. Size int
  67. User string
  68. Password string
  69. }
  70. type mysql struct {
  71. Addr string
  72. DbnameBasic string
  73. DbnameMedical string
  74. Size int
  75. User string
  76. Password string
  77. }
  78. type duration struct {
  79. time.Duration
  80. }
  81. // UnmarshalText parse 10s to time.Time
  82. func (d *duration) UnmarshalText(text []byte) error {
  83. var err error
  84. d.Duration, err = time.ParseDuration(string(text))
  85. return err
  86. }