config file update

This commit is contained in:
Gordon 2022-08-01 16:56:06 +08:00
parent 4003befc2a
commit 22a39ed4d3

View File

@ -512,15 +512,28 @@ type PDefaultTips struct {
func init() { func init() {
cfgName := os.Getenv("CONFIG_NAME") cfgName := os.Getenv("CONFIG_NAME")
if len(cfgName) != 0 {
Root = cfgName
}
fmt.Println("GET IM DEFAULT CONFIG PATH :", Root, "ENV PATH:", cfgName) fmt.Println("GET IM DEFAULT CONFIG PATH :", Root, "ENV PATH:", cfgName)
bytes, err := ioutil.ReadFile(filepath.Join(Root, "config", "config.yaml")) if len(cfgName) != 0 {
if err != nil { bytes, err := ioutil.ReadFile(filepath.Join(cfgName, "config", "config.yaml"))
panic(err.Error()) if err != nil {
} bytes, err = ioutil.ReadFile(filepath.Join(Root, "config", "config.yaml"))
if err = yaml.Unmarshal(bytes, &Config); err != nil { if err != nil {
panic(err.Error()) panic(err.Error())
}
} else {
Root = cfgName
}
if err = yaml.Unmarshal(bytes, &Config); err != nil {
panic(err.Error())
}
} else {
bytes, err := ioutil.ReadFile(filepath.Join(Root, "config", "config.yaml"))
if err != nil {
panic(err.Error())
}
if err = yaml.Unmarshal(bytes, &Config); err != nil {
panic(err.Error())
}
} }
} }