conf.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package conf
  2. import (
  3. "github.com/product-definition/utils/base"
  4. "gopkg.in/yaml.v2"
  5. "io/ioutil"
  6. "path"
  7. "runtime"
  8. )
  9. //支持数组,工具
  10. type TConf struct {
  11. LogLevel string `yaml:"loglevel"`
  12. Redis struct {
  13. Addr string `yaml:"addr"`
  14. }
  15. Mysql struct {
  16. Addr string `yaml:"addr"`
  17. User string `yaml:"user"`
  18. PassWord string `yaml:"password"`
  19. DataBase string `yaml:"database"`
  20. MaxIdleConns int `yaml:"maxidleconns"`
  21. MaxOpenConns int `yaml:"maxopenconns"`
  22. }
  23. Port string
  24. Nsq struct {
  25. Addr string `yaml:"addr"`
  26. MaxAttempts uint16 `yaml:"maxAttempts"`
  27. }
  28. Task struct {
  29. StationTaskCron string `yaml:"stationTaskCron"`
  30. EmptyOffTaskCron string `yaml:"emptyOffTaskCron"`
  31. InvertBoxTaskCron string `yaml:"invertBoxTaskCron"`
  32. }
  33. Warehouse struct {
  34. }
  35. Elastic struct {
  36. Addr string
  37. User string
  38. Pass string
  39. }
  40. }
  41. var Conf TConf
  42. func init() {
  43. yamlFile, err := ioutil.ReadFile(getCurrentPath() + "/conf.yaml")
  44. if err != nil {
  45. base.PanicfLogger(nil, "yamlfile get error: %v ", err)
  46. }
  47. err = yaml.Unmarshal(yamlFile, &Conf)
  48. if err != nil {
  49. base.PanicfLogger(nil, "yaml unmarshal error: %v", err)
  50. }
  51. }
  52. func getCurrentPath() string {
  53. _, filename, _, _ := runtime.Caller(1)
  54. return path.Dir(filename)
  55. }