完成配量读取配置文件
This commit is contained in:
parent
e610e02d45
commit
879c9df7cc
40
client.go
40
client.go
@ -77,20 +77,27 @@ func (c *client) getMysqlCfgFileList(cfgDir string) ([]cfgFile, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fileType := strings.ToLower(fileArr[len(fileArr)-1])
|
fileType := strings.ToLower(fileArr[len(fileArr)-1])
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
cfgInfo := cfgFile{
|
||||||
|
Path: filepathNames[i],
|
||||||
|
Type: FileTypeYaml,
|
||||||
|
Config: Mysql{},
|
||||||
|
}
|
||||||
switch fileType {
|
switch fileType {
|
||||||
case FileTypeYaml:
|
case FileTypeYaml:
|
||||||
fallthrough
|
fallthrough
|
||||||
case FileTypeYml:
|
case FileTypeYml:
|
||||||
cfgFileList = append(cfgFileList, cfgFile{
|
cfgInfo.Type = FileTypeYaml
|
||||||
Path: filepathNames[i],
|
if err = util.File.ReadYmlContent(filepathNames[i], &cfgInfo); nil != err {
|
||||||
Type: FileTypeYaml,
|
return nil, fmt.Errorf("%s 配置文件解析失败, 原因 : %s", cfgInfo.Path, err.Error())
|
||||||
})
|
}
|
||||||
util.File.ReadYmlConfig()
|
|
||||||
case FileTypeJson:
|
case FileTypeJson:
|
||||||
cfgFileList = append(cfgFileList, cfgFile{
|
cfgInfo.Type = FileTypeJson
|
||||||
Path: filepathNames[i],
|
if err = util.File.ReadJSONContent(filepathNames[i], &cfgInfo); nil != err {
|
||||||
Type: FileTypeJson,
|
return nil, fmt.Errorf("%s 配置文件解析失败, 原因 : %s", cfgInfo.Path, err.Error())
|
||||||
})
|
}
|
||||||
default:
|
default:
|
||||||
// 不是JSON , 也不是YML, 跳过
|
// 不是JSON , 也不是YML, 跳过
|
||||||
continue
|
continue
|
||||||
@ -104,7 +111,7 @@ func (c *client) getMysqlCfgFileList(cfgDir string) ([]cfgFile, error) {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 19:32 2022/6/5
|
// 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()
|
c.lock.RLock()
|
||||||
defer c.lock.RUnlock()
|
defer c.lock.RUnlock()
|
||||||
var (
|
var (
|
||||||
@ -127,7 +134,7 @@ func (c *client) GetMasterClient(ctx *gin.Context, dbFlag string) (*gorm.DB, err
|
|||||||
err error
|
err error
|
||||||
dbClient *DBClient
|
dbClient *DBClient
|
||||||
)
|
)
|
||||||
if dbClient, err = c.GetDBClient(ctx, dbFlag); nil != err {
|
if dbClient, err = c.GetDBClient(dbFlag); nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +153,7 @@ func (c *client) GetSlaveClient(ctx *gin.Context, dbFlag string) (*gorm.DB, erro
|
|||||||
err error
|
err error
|
||||||
dbClient *DBClient
|
dbClient *DBClient
|
||||||
)
|
)
|
||||||
if dbClient, err = c.GetDBClient(ctx, dbFlag); nil != err {
|
if dbClient, err = c.GetDBClient(dbFlag); nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,15 +197,6 @@ func (c *client) getGormClient() (*gorm.DB, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// BatchNewDBClient 批量设置数据库实例, 读取指定目录下的yaml文件, 文件名作为标识, 内容是数据库具体配置
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 15:43 2022/6/5
|
|
||||||
func BatchNewDBClient(dbConfigDir string) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewDBClient ...
|
// NewDBClient ...
|
||||||
//
|
//
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
1
go.mod
1
go.mod
@ -14,7 +14,6 @@ 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
|
||||||
|
4
go.sum
4
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 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/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 h1:yAxxukVUdSM5wn264el+QiAEB0OBN/5H7Xw9Z6rLzUY=
|
||||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220609072516-022a755fdf2f/go.mod h1:YI/XeTmrr9+8dxa4ThPkmNcEE8WHG5pZkKujpSWwIxM=
|
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=
|
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||||
|
Loading…
Reference in New Issue
Block a user