From 879c9df7ccf52c6740678c6f0fde3b2e90da8486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 11 Jun 2022 18:00:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E9=85=8D=E9=87=8F=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 40 +++++++++++++++++++--------------------- go.mod | 1 - go.sum | 4 ---- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/client.go b/client.go index a2190e1..3e608b4 100644 --- a/client.go +++ b/client.go @@ -77,20 +77,27 @@ func (c *client) getMysqlCfgFileList(cfgDir string) ([]cfgFile, error) { continue } fileType := strings.ToLower(fileArr[len(fileArr)-1]) + var ( + err error + ) + cfgInfo := cfgFile{ + Path: filepathNames[i], + Type: FileTypeYaml, + Config: Mysql{}, + } switch fileType { case FileTypeYaml: fallthrough case FileTypeYml: - cfgFileList = append(cfgFileList, cfgFile{ - Path: filepathNames[i], - Type: FileTypeYaml, - }) - util.File.ReadYmlConfig() + cfgInfo.Type = FileTypeYaml + if err = util.File.ReadYmlContent(filepathNames[i], &cfgInfo); nil != err { + return nil, fmt.Errorf("%s 配置文件解析失败, 原因 : %s", cfgInfo.Path, err.Error()) + } case FileTypeJson: - cfgFileList = append(cfgFileList, cfgFile{ - Path: filepathNames[i], - Type: FileTypeJson, - }) + cfgInfo.Type = FileTypeJson + if err = util.File.ReadJSONContent(filepathNames[i], &cfgInfo); nil != err { + return nil, fmt.Errorf("%s 配置文件解析失败, 原因 : %s", cfgInfo.Path, err.Error()) + } default: // 不是JSON , 也不是YML, 跳过 continue @@ -104,7 +111,7 @@ func (c *client) getMysqlCfgFileList(cfgDir string) ([]cfgFile, error) { // Author : go_developer@163.com<白茶清欢> // // Date : 19:32 2022/6/5 -func (c *client) GetDBClient(ctx *gin.Context, dbFlag string) (*DBClient, error) { +func (c *client) GetDBClient(dbFlag string) (*DBClient, error) { c.lock.RLock() defer c.lock.RUnlock() var ( @@ -127,7 +134,7 @@ func (c *client) GetMasterClient(ctx *gin.Context, dbFlag string) (*gorm.DB, err err error dbClient *DBClient ) - if dbClient, err = c.GetDBClient(ctx, dbFlag); nil != err { + if dbClient, err = c.GetDBClient(dbFlag); nil != err { return nil, err } @@ -146,7 +153,7 @@ func (c *client) GetSlaveClient(ctx *gin.Context, dbFlag string) (*gorm.DB, erro err error dbClient *DBClient ) - if dbClient, err = c.GetDBClient(ctx, dbFlag); nil != err { + if dbClient, err = c.GetDBClient(dbFlag); nil != err { return nil, err } @@ -190,15 +197,6 @@ func (c *client) getGormClient() (*gorm.DB, error) { return nil, nil } -// BatchNewDBClient 批量设置数据库实例, 读取指定目录下的yaml文件, 文件名作为标识, 内容是数据库具体配置 -// -// Author : go_developer@163.com<白茶清欢> -// -// Date : 15:43 2022/6/5 -func BatchNewDBClient(dbConfigDir string) { - -} - // NewDBClient ... // // Author : go_developer@163.com<白茶清欢> diff --git a/go.mod b/go.mod index 8e08cef..961b22f 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ 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 d6718ad..29b4d74 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +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= -git.zhangdeman.cn/zhangdeman/util v0.0.0-20220514082633-1be4d9eab11f/go.mod h1:YI/XeTmrr9+8dxa4ThPkmNcEE8WHG5pZkKujpSWwIxM= git.zhangdeman.cn/zhangdeman/util v0.0.0-20220609072516-022a755fdf2f h1:yAxxukVUdSM5wn264el+QiAEB0OBN/5H7Xw9Z6rLzUY= git.zhangdeman.cn/zhangdeman/util v0.0.0-20220609072516-022a755fdf2f/go.mod h1:YI/XeTmrr9+8dxa4ThPkmNcEE8WHG5pZkKujpSWwIxM= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=