1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package conf
- import (
- "base-gin/utils/base"
- "gopkg.in/yaml.v2"
- "io/ioutil"
- "path"
- "runtime"
- )
- //支持数组,工具
- type TConf struct {
- LogLevel string `yaml:"loglevel"`
- Mysql struct {
- Addr string `yaml:"addr"`
- User string `yaml:"user"`
- PassWord string `yaml:"password"`
- DataBase string `yaml:"database"`
- MaxIdleConns int `yaml:"maxidleconns"`
- MaxOpenConns int `yaml:"maxopenconns"`
- }
- }
- var Conf TConf
- func init() {
- yamlFile, err := ioutil.ReadFile(getCurrentPath() + "/conf.yaml")
- if err != nil {
- base.PanicfLogger(nil, "yamlfile get error: %v ", err)
- }
- err = yaml.Unmarshal(yamlFile, &Conf)
- if err != nil {
- base.PanicfLogger(nil, "yaml unmarshal error: %v", err)
- }
- }
- func getCurrentPath() string {
- _, filename, _, _ := runtime.Caller(1)
- return path.Dir(filename)
- }
|