conf.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. Udp udp
  22. DB db
  23. Mail mail
  24. Log log
  25. }
  26. type udp struct {
  27. LocPort string
  28. }
  29. type mail struct {
  30. Send bool
  31. To string
  32. Api string
  33. }
  34. // Log Config
  35. type log struct {
  36. LogPath string
  37. MaxSize int
  38. Compress bool
  39. MaxAge int
  40. MaxBackups int
  41. LogLevel string
  42. Format string
  43. }
  44. type db struct {
  45. MongoB mgo
  46. MongoP mgo
  47. Mysql mysql
  48. }
  49. type mgo struct {
  50. Addr string
  51. Dbname string
  52. Size int
  53. User string
  54. Password string
  55. }
  56. type mysql struct {
  57. Addr string
  58. Dbname string
  59. Size int
  60. User string
  61. Password string
  62. }
  63. type duration struct {
  64. time.Duration
  65. }
  66. // UnmarshalText parse 10s to time.Time
  67. func (d *duration) UnmarshalText(text []byte) error {
  68. var err error
  69. d.Duration, err = time.ParseDuration(string(text))
  70. return err
  71. }