From 9377cd288f699849da3d3af3ed7d53c354c01d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 9 Jun 2022 14:58:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 37 +++++++++++++++++++++++++++++++++++++ define.go | 19 +++++++++++++++++++ go.mod | 1 + go.sum | 2 ++ 4 files changed, 59 insertions(+) diff --git a/client.go b/client.go index 1a5d481..98e4c47 100644 --- a/client.go +++ b/client.go @@ -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<白茶清欢> diff --git a/define.go b/define.go index f2eae64..b9f5726 100644 --- a/define.go +++ b/define.go @@ -51,3 +51,22 @@ type LogConfig struct { TraceFieldName string Skip int } + +// cfgFile 配置文件定义 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:47 2022/6/9 +type cfgFile struct { + Path string `json:"path"` // 配置文件路径 + Type string `json:"type"` // 配置文件类型 +} + +const ( + // FileTypeYml tml + FileTypeYml = "yml" + // FileTypeYaml yaml + FileTypeYaml = "yaml" + // FileTypeJson json + FileTypeJson = "json" +) diff --git a/go.mod b/go.mod index 287c55e..be718ad 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( ) require ( + git.zhangdeman.cn/zhangdeman/command v0.0.0-20220522141301-bced9bb50647 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.13.0 // indirect github.com/go-playground/universal-translator v0.17.0 // indirect diff --git a/go.sum b/go.sum index 82ba6d4..c3993c8 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +git.zhangdeman.cn/zhangdeman/command v0.0.0-20220522141301-bced9bb50647 h1:TQhXffwAtgJIyu7FuPdmgX6F7OoCGIujW8aN3EFODpw= +git.zhangdeman.cn/zhangdeman/command v0.0.0-20220522141301-bced9bb50647/go.mod h1:oCRPD8pwzLidtrqKQXcHMMJocYs5WDXnh20SCu34cBo= git.zhangdeman.cn/zhangdeman/logger v0.0.0-20220514052229-cf395d3dc4c3 h1:T41tE9F2Gy8eKVSKtTPhf7RaRT12qHEXTfx4IJuoIS4= git.zhangdeman.cn/zhangdeman/logger v0.0.0-20220514052229-cf395d3dc4c3/go.mod h1:0A5BV9pE31nuFE60TLbP7BIhhV/fcWoi+fHrcV2clJw= git.zhangdeman.cn/zhangdeman/util v0.0.0-20220514082633-1be4d9eab11f h1:1amgaCqOPn7gvcUEEX614cO8lkIz+G8W/YtGXLIdW1w=