conf.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. Record string
  56. Size int
  57. User string
  58. Password string
  59. }
  60. type redis struct {
  61. Addr string
  62. Db int
  63. }
  64. type duration struct {
  65. time.Duration
  66. }
  67. // UnmarshalText parse 10s to time.Time
  68. func (d *duration) UnmarshalText(text []byte) error {
  69. var err error
  70. d.Duration, err = time.ParseDuration(string(text))
  71. return err
  72. }