conf.go 1.1 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. Serve serve
  22. DB db
  23. Log log
  24. }
  25. type serve struct {
  26. Thread int
  27. }
  28. // Log Config
  29. type log struct {
  30. LogPath string
  31. MaxSize int
  32. Compress bool
  33. MaxAge int
  34. MaxBackups int
  35. LogLevel string
  36. Format string
  37. }
  38. type db struct {
  39. Mongo mgo
  40. Mysql mysql
  41. Redis redis
  42. }
  43. type mgo struct {
  44. Addr string
  45. Dbname string
  46. Coll string
  47. SaveColl string
  48. Size int
  49. User string
  50. Password string
  51. }
  52. type mysql struct {
  53. Addr string
  54. Dbname string
  55. Size int
  56. User string
  57. Password string
  58. }
  59. type redis struct {
  60. Addr string
  61. Code 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. }