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 ...