From 34e12b13500165df1ef83b83dbb84989e5bcc8a7 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, 22 Jun 2022 21:34:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=89=E7=A7=8Dredis?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index afbb57b..76ac6ce 100644 --- a/client.go +++ b/client.go @@ -27,13 +27,63 @@ var ( Client ClientInterface ) -func init() { - Client = &OwnClient{ +// InitWithCfgFile 使用配置文件初始化 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 21:24 2022/6/22 +func InitWithCfgFile(cfgFilePath string) error { + c := &OwnClient{ lock: &sync.RWMutex{}, instanceTable: make(map[string]*RealClient), confTable: make(map[string]*FullConfig), parseErrorFunc: defaultParseError, } + if err := c.loadConfig(cfgFilePath); nil != err { + return err + } + Client = c + return nil +} + +// InitWithCfgDir 使用配置目录初始化 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 21:31 2022/6/22 +func InitWithCfgDir(cfgDir string) error { + c := &OwnClient{ + lock: &sync.RWMutex{}, + instanceTable: make(map[string]*RealClient), + confTable: make(map[string]*FullConfig), + parseErrorFunc: defaultParseError, + } + if err := c.batchLoadConfig(cfgDir); nil != err { + return err + } + Client = c + return nil +} + +// InitWithCfgFileList 使用批量的配置文件初始化 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 21:33 2022/6/22 +func InitWithCfgFileList(cfgFileList []string) error { + c := &OwnClient{ + lock: &sync.RWMutex{}, + instanceTable: make(map[string]*RealClient), + confTable: make(map[string]*FullConfig), + parseErrorFunc: defaultParseError, + } + for _, cfgFilePath := range cfgFileList { + if err := c.loadConfig(cfgFilePath); nil != err { + return err + } + } + Client = c + return nil } // defaultParseError ...