conf.go 1.2 KB

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