增加三种redis初始化方式

This commit is contained in:
白茶清欢 2022-06-22 21:34:16 +08:00
parent bcecf65832
commit 34e12b1350

View File

@ -27,13 +27,63 @@ var (
Client ClientInterface Client ClientInterface
) )
func init() { // InitWithCfgFile 使用配置文件初始化
Client = &OwnClient{ //
// Author : go_developer@163.com<白茶清欢>
//
// Date : 21:24 2022/6/22
func InitWithCfgFile(cfgFilePath string) error {
c := &OwnClient{
lock: &sync.RWMutex{}, lock: &sync.RWMutex{},
instanceTable: make(map[string]*RealClient), instanceTable: make(map[string]*RealClient),
confTable: make(map[string]*FullConfig), confTable: make(map[string]*FullConfig),
parseErrorFunc: defaultParseError, 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 ... // defaultParseError ...