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