conf.go 1.2 KB

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