conf.go 933 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. DB Db
  22. Log Log
  23. }
  24. // Log Config
  25. type Log struct {
  26. LogPath string
  27. MaxSize int
  28. Compress bool
  29. MaxAge int
  30. MaxBackups int
  31. LogLevel string
  32. Format string
  33. }
  34. type Db struct {
  35. Mongo mgo
  36. Mysql mysql
  37. }
  38. type mgo struct {
  39. Addr string
  40. Dbname string
  41. Size int
  42. User string
  43. Password string
  44. }
  45. type mysql struct {
  46. Addr string
  47. Dbname string
  48. Size int
  49. User string
  50. Password string
  51. }
  52. type duration struct {
  53. time.Duration
  54. }
  55. // UnmarshalText parse 10s to time.Time
  56. func (d *duration) UnmarshalText(text []byte) error {
  57. var err error
  58. d.Duration, err = time.ParseDuration(string(text))
  59. return err
  60. }