增加获取配置文件的方法
This commit is contained in:
		
							
								
								
									
										37
									
								
								client.go
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								client.go
									
									
									
									
									
								
							| @ -9,6 +9,8 @@ package mysql | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  | 	"path/filepath" | ||||||
|  | 	"strings" | ||||||
| 	"sync" | 	"sync" | ||||||
|  |  | ||||||
| 	"git.zhangdeman.cn/zhangdeman/logger/wrapper" | 	"git.zhangdeman.cn/zhangdeman/logger/wrapper" | ||||||
| @ -58,6 +60,41 @@ func (c *client) BatchAddWithConfigDir(cfgDir string) error { | |||||||
| 	return nil | 	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 | // GetDBClient 获取db client | ||||||
| // | // | ||||||
| // Author : go_developer@163.com<白茶清欢> | // Author : go_developer@163.com<白茶清欢> | ||||||
|  | |||||||
							
								
								
									
										19
									
								
								define.go
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								define.go
									
									
									
									
									
								
							| @ -51,3 +51,22 @@ type LogConfig struct { | |||||||
| 	TraceFieldName   string | 	TraceFieldName   string | ||||||
| 	Skip             int | 	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" | ||||||
|  | ) | ||||||
|  | |||||||
							
								
								
									
										1
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								go.mod
									
									
									
									
									
								
							| @ -14,6 +14,7 @@ require ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| require ( | require ( | ||||||
|  | 	git.zhangdeman.cn/zhangdeman/command v0.0.0-20220522141301-bced9bb50647 // indirect | ||||||
| 	github.com/gin-contrib/sse v0.1.0 // indirect | 	github.com/gin-contrib/sse v0.1.0 // indirect | ||||||
| 	github.com/go-playground/locales v0.13.0 // indirect | 	github.com/go-playground/locales v0.13.0 // indirect | ||||||
| 	github.com/go-playground/universal-translator v0.17.0 // indirect | 	github.com/go-playground/universal-translator v0.17.0 // indirect | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								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 h1:T41tE9F2Gy8eKVSKtTPhf7RaRT12qHEXTfx4IJuoIS4= | ||||||
| git.zhangdeman.cn/zhangdeman/logger v0.0.0-20220514052229-cf395d3dc4c3/go.mod h1:0A5BV9pE31nuFE60TLbP7BIhhV/fcWoi+fHrcV2clJw= | 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= | git.zhangdeman.cn/zhangdeman/util v0.0.0-20220514082633-1be4d9eab11f h1:1amgaCqOPn7gvcUEEX614cO8lkIz+G8W/YtGXLIdW1w= | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user