conf.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. Mysql mysql
  42. Es es
  43. }
  44. type mgo struct {
  45. Addr string
  46. Dbname string
  47. Coll string
  48. Pcoll string
  49. Size int
  50. User string
  51. Password string
  52. }
  53. type mysql struct {
  54. Addr string
  55. Dbname string
  56. Coll string
  57. Pcoll string
  58. Size int
  59. User string
  60. Password string
  61. }
  62. type es struct {
  63. Addr string
  64. User string
  65. Password string
  66. Size int
  67. Index string
  68. }
  69. type duration struct {
  70. time.Duration
  71. }
  72. // UnmarshalText parse 10s to time.Time
  73. func (d *duration) UnmarshalText(text []byte) error {
  74. var err error
  75. d.Duration, err = time.ParseDuration(string(text))
  76. return err
  77. }