12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package conf
- import (
- "github.com/product-definition/utils/base"
- "gopkg.in/yaml.v2"
- "io/ioutil"
- "path"
- "runtime"
- )
- //支持数组,工具
- type TConf struct {
- LogLevel string `yaml:"loglevel"`
- Redis struct {
- Addr string `yaml:"addr"`
- }
- 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"`
- }
- Port string
- Nsq struct {
- Addr string `yaml:"addr"`
- MaxAttempts uint16 `yaml:"maxAttempts"`
- }
- Task struct {
- StationTaskCron string `yaml:"stationTaskCron"`
- EmptyOffTaskCron string `yaml:"emptyOffTaskCron"`
- InvertBoxTaskCron string `yaml:"invertBoxTaskCron"`
- }
- Warehouse struct {
- }
- Elastic struct {
- Addr string
- User string
- Pass string
- }
- }
- 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)
- }
|