1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00

feat: support expand env

This commit is contained in:
wdvxdr 2021-12-06 22:30:40 +08:00
parent 0ead592114
commit aa2caac3f7
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6

View File

@ -149,11 +149,11 @@ type MongoDBConfig struct {
func Parse(path string) *Config {
fromEnv := os.Getenv("GCQ_UIN") != ""
file, err := os.Open(path)
file, err := os.ReadFile(path)
config := &Config{}
if err == nil {
defer func() { _ = file.Close() }()
if err = yaml.NewDecoder(file).Decode(config); err != nil && !fromEnv {
err = yaml.NewDecoder(strings.NewReader(os.ExpandEnv(string(file)))).Decode(config)
if err != nil && !fromEnv {
log.Fatal("配置文件不合法!", err)
}
} else if !fromEnv {