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:
parent
0ead592114
commit
aa2caac3f7
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user