conf.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. Crontab string
  66. }
  67. type alarm struct {
  68. IsOpen bool
  69. Address string
  70. Toppic string
  71. IsJsonEncode bool
  72. Id string
  73. Title string
  74. Text string
  75. }
  76. // UnmarshalText parse 10s to time.Time
  77. func (d *duration) UnmarshalText(text []byte) error {
  78. var err error
  79. d.Duration, err = time.ParseDuration(string(text))
  80. return err
  81. }