conf.go 957 B

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