conf.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package config
  2. import (
  3. "fmt"
  4. "os"
  5. "time"
  6. "github.com/BurntSushi/toml"
  7. )
  8. var (
  9. Conf *conf
  10. )
  11. // Init Config
  12. func Init(conf string) {
  13. _, err := toml.DecodeFile(conf, &Conf)
  14. if err != nil {
  15. fmt.Printf("Err %v", err)
  16. os.Exit(1)
  17. }
  18. }
  19. type conf struct {
  20. DB db
  21. Log log
  22. Info info
  23. Alarm alarm
  24. }
  25. // Log Config
  26. type log struct {
  27. LogPath string
  28. MaxSize int
  29. Compress bool
  30. MaxAge int
  31. MaxBackups int
  32. LogLevel string
  33. Format string
  34. }
  35. type db struct {
  36. MongoP mgo
  37. Mysql mysql
  38. Redis redis
  39. }
  40. type redis struct {
  41. Address string
  42. }
  43. type mgo struct {
  44. Addr string
  45. Dbname string
  46. Size int
  47. User string
  48. Password string
  49. }
  50. type mysql struct {
  51. Addr string
  52. Dbname string
  53. Size int
  54. User string
  55. Password string
  56. }
  57. type duration struct {
  58. time.Duration
  59. }
  60. type info struct {
  61. ProjectsetIdGt string
  62. ProjectsetIdLt string
  63. Ch int //并发
  64. TableName string //表名 projectset
  65. }
  66. type alarm struct {
  67. IsOpen bool
  68. Address string
  69. Toppic string
  70. IsJsonEncode bool
  71. Id string
  72. Title string
  73. Text string
  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. }