From 374fdac47792651bbb595936691b8d244cbdaaf9 Mon Sep 17 00:00:00 2001 From: ayflying Date: Wed, 14 May 2025 16:22:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E4=B8=BB=E6=9C=BA=E6=9F=A5?= =?UTF-8?q?=E6=89=BE=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=EF=BC=8C=E6=9C=80?= =?UTF-8?q?=E9=AB=985=E7=BA=A7=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/config/config.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 4efba6f..f1891f7 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -86,14 +86,19 @@ func (c *Cfg) GetFile(filename string, _pathStr ...string) (jsonObj *gjson.Json, bytes = gres.GetContent(filePath) // 从打包资源中获取内容 } - //如果还是没有读取到配置,从当前目录返回上级读取 - if bytes == nil { - // 上级拼接完整的文件路径 - filePath = "../../" + filePath - if gfile.IsFile(filePath) { - bytes = gfile.GetBytes(filePath) // 读取物理文件内容 + for range 5 { + //如果还是没有读取到配置,从当前目录返回上级读取 + if bytes == nil { + // 上级拼接完整的文件路径 + filePath = "../" + filePath + if gfile.IsFile(filePath) { + bytes = gfile.GetBytes(filePath) // 读取物理文件内容 + //找到配置了,跳过 + break + } } } + // 解析 JSON 内容并返回结果 jsonObj, err = gjson.DecodeToJson(bytes) return