mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 11:33:48 +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 {
|
func Parse(path string) *Config {
|
||||||
fromEnv := os.Getenv("GCQ_UIN") != ""
|
fromEnv := os.Getenv("GCQ_UIN") != ""
|
||||||
|
|
||||||
file, err := os.Open(path)
|
file, err := os.ReadFile(path)
|
||||||
config := &Config{}
|
config := &Config{}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
defer func() { _ = file.Close() }()
|
err = yaml.NewDecoder(strings.NewReader(os.ExpandEnv(string(file)))).Decode(config)
|
||||||
if err = yaml.NewDecoder(file).Decode(config); err != nil && !fromEnv {
|
if err != nil && !fromEnv {
|
||||||
log.Fatal("配置文件不合法!", err)
|
log.Fatal("配置文件不合法!", err)
|
||||||
}
|
}
|
||||||
} else if !fromEnv {
|
} else if !fromEnv {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user