From e3c06731e76257cf5937dea1a8787635ec1619fa Mon Sep 17 00:00:00 2001 From: null-su <57587884+null-su@users.noreply.github.com> Date: Sat, 10 Apr 2021 11:37:32 +0800 Subject: [PATCH] fix config.Get() (#808) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 配置文件不存在时config.Get()返回非空指针, 导致无法创建默认配置文件 --- global/config/config.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/global/config/config.go b/global/config/config.go index 26849e5..5a8935c 100644 --- a/global/config/config.go +++ b/global/config/config.go @@ -122,9 +122,11 @@ func Get() *Config { file, err := os.Open(DefaultConfigFile) if err != nil { log.Error("获取配置文件失败: ", err) + return } + defer file.Close() config = &Config{} - if yaml.NewDecoder(file).Decode(config) != nil { + if err = yaml.NewDecoder(file).Decode(config); err != nil { log.Fatal("配置文件不合法!", err) } })