From 54978499001602e92620c7a789db4dc09d8a8a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Wed, 15 Jun 2022 16:47:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8D=95=E7=82=B9=E4=B8=8E?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E8=BD=BD=E5=85=A5=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/client.go b/client.go index 1a8dbd1..f8f697f 100644 --- a/client.go +++ b/client.go @@ -115,7 +115,7 @@ type OwnClient struct { // Author : go_developer@163.com<白茶清欢> // // Date : 14:31 2022/6/15 -func (c *OwnClient) loadConfig(cfgPath string) (*FullConfig, error) { +func (c *OwnClient) loadConfig(cfgPath string) error { var ( err error cfg FullConfig @@ -123,12 +123,12 @@ func (c *OwnClient) loadConfig(cfgPath string) (*FullConfig, error) { filePathArr := strings.Split(cfgPath, string(filepath.Separator)) if len(filePathArr) == 0 { - return nil, CfgFilePathError() + return CfgFilePathError() } fileName := strings.ToLower(filePathArr[len(filePathArr)-1]) fileArr := strings.Split(fileName, ".") if len(filePathArr) < 2 { - return nil, CfgFileFormatErr("未知") + return CfgFileFormatErr("未知") } flag := strings.Trim( strings.Trim( @@ -137,22 +137,39 @@ func (c *OwnClient) loadConfig(cfgPath string) (*FullConfig, error) { switch strings.ToLower(fileArr[len(fileArr)-1]) { case "json": if err = util.File.ReadJSONContent(cfgPath, &cfg); nil != err { - return nil, err + return err } flag = strings.Join(fileArr[0:len(fileArr)-1], ".") case "yml": fallthrough case "yaml": if err = util.File.ReadYmlContent(cfgPath, &cfg); nil != err { - return nil, err + return err } flag = strings.Join(fileArr[0:len(fileArr)-1], ".") default: - return nil, CfgFileFormatErr(fileArr[len(fileArr)-1]) + return CfgFileFormatErr(fileArr[len(fileArr)-1]) } + c.lock.Lock() c.confTable[flag] = &cfg - return &cfg, nil + c.lock.Unlock() + return nil +} + +// batchLoadConfig 批量载入配置 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 16:44 2022/6/15 +func (c *OwnClient) batchLoadConfig(cfgDir string) error { + filepathNames, _ := filepath.Glob(filepath.Join(cfgDir, "*")) + for i := range filepathNames { + if err := c.loadConfig(filepathNames[i]); nil != err { + return err + } + } + return nil } // init 初始化redis连接