conf.go 837 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package conf
  2. import (
  3. "base-gin/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. Mysql struct {
  13. Addr string `yaml:"addr"`
  14. User string `yaml:"user"`
  15. PassWord string `yaml:"password"`
  16. DataBase string `yaml:"database"`
  17. MaxIdleConns int `yaml:"maxidleconns"`
  18. MaxOpenConns int `yaml:"maxopenconns"`
  19. }
  20. }
  21. var Conf TConf
  22. func init() {
  23. yamlFile, err := ioutil.ReadFile(getCurrentPath() + "/conf.yaml")
  24. if err != nil {
  25. base.PanicfLogger(nil, "yamlfile get error: %v ", err)
  26. }
  27. err = yaml.Unmarshal(yamlFile, &Conf)
  28. if err != nil {
  29. base.PanicfLogger(nil, "yaml unmarshal error: %v", err)
  30. }
  31. }
  32. func getCurrentPath() string {
  33. _, filename, _, _ := runtime.Caller(1)
  34. return path.Dir(filename)
  35. }