增加获取配置文件的方法

This commit is contained in:
2022-06-09 14:58:01 +08:00
parent 2709cd41e7
commit 9377cd288f
4 changed files with 59 additions and 0 deletions

View File

@ -9,6 +9,8 @@ package mysql
import (
"fmt"
"path/filepath"
"strings"
"sync"
"git.zhangdeman.cn/zhangdeman/logger/wrapper"
@ -58,6 +60,41 @@ func (c *client) BatchAddWithConfigDir(cfgDir string) error {
return nil
}
// getMysqlCfgFileList 获取mysql配置文件列表
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:39 2022/6/9
func (c *client) getMysqlCfgFileList(cfgDir string) ([]cfgFile, error) {
filepathNames, _ := filepath.Glob(filepath.Join(cfgDir, "*"))
cfgFileList := make([]cfgFile, 0)
for i := range filepathNames {
fileArr := strings.Split(filepathNames[i], ".")
if len(fileArr) < 2 {
// 获取不到类型
continue
}
fileType := strings.ToLower(fileArr[len(fileArr)-1])
switch fileType {
case FileTypeYaml:
fallthrough
case FileTypeYml:
cfgFileList = append(cfgFileList, cfgFile{
Path: filepathNames[i],
Type: FileTypeYaml,
})
case FileTypeJson:
cfgFileList = append(cfgFileList, cfgFile{
Path: filepathNames[i],
Type: FileTypeJson,
})
default:
continue
}
}
return cfgFileList, nil
}
// GetDBClient 获取db client
//
// Author : go_developer@163.com<白茶清欢>