fusenapi/utils/fsconfig/config.go

54 lines
918 B
Go
Raw Normal View History

2023-09-18 10:44:12 +00:00
package fsconfig
import (
"fmt"
"log"
"os"
"gopkg.in/yaml.v2"
)
type EnvConfig struct {
Host string `yaml:"host"`
Port uint64 `yaml:"port"`
UserName string `yaml:"username"`
Password string `yaml:"password"`
NamespaceId string `yaml:"namespace"`
DataId string `yaml:"dataid"`
Group string `yaml:"group"`
}
var OptPathDir = "/opt"
var nacosConfig *EnvConfig
func GetEnvCofing() *EnvConfig {
return nacosConfig
}
func init() {
if OptPathDir[len(OptPathDir)-1] != '/' {
OptPathDir = OptPathDir + "/"
}
for _, yname := range []string{"env.yaml", "env.yml"} {
f, err := os.Open(OptPathDir + "/" + yname)
if err != nil {
log.Println(err)
continue
}
cfg := &EnvConfig{}
err = yaml.NewDecoder(f).Decode(&cfg)
if err != nil {
log.Println(err)
continue
}
nacosConfig = cfg
return
}
panic(fmt.Sprintf("can't find %s(env.yaml|env.yml) ", OptPathDir))
}