conf.go 998 B

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