增加批量读取配置 TODO : 待完成

This commit is contained in:
白茶清欢 2022-06-11 17:49:43 +08:00
parent 9377cd288f
commit e610e02d45
4 changed files with 46 additions and 13 deletions

View File

@ -13,6 +13,8 @@ import (
"strings"
"sync"
"git.zhangdeman.cn/zhangdeman/util"
"git.zhangdeman.cn/zhangdeman/logger/wrapper"
"github.com/gin-gonic/gin"
@ -83,12 +85,14 @@ func (c *client) getMysqlCfgFileList(cfgDir string) ([]cfgFile, error) {
Path: filepathNames[i],
Type: FileTypeYaml,
})
util.File.ReadYmlConfig()
case FileTypeJson:
cfgFileList = append(cfgFileList, cfgFile{
Path: filepathNames[i],
Type: FileTypeJson,
})
default:
// 不是JSON , 也不是YML, 跳过
continue
}
}

View File

@ -27,16 +27,6 @@ type DBConfig struct {
Connection Connection `json:"connection" yaml:"connection"` // 连接数量配置
}
// Connection 连接数配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 19:05 2022/6/5
type Connection struct {
MaxOpen int `json:"max_open" yaml:"max_open"` // 打开的最大连接数
MaxIdle int `json:"max_idle" yaml:"max_idle"` // 最大空闲连接数
}
// LogConfig 日志配置
//
// Author : go_developer@163.com<白茶清欢>
@ -58,8 +48,9 @@ type LogConfig struct {
//
// Date : 14:47 2022/6/9
type cfgFile struct {
Path string `json:"path"` // 配置文件路径
Type string `json:"type"` // 配置文件类型
Path string `json:"path"` // 配置文件路径
Type string `json:"type"` // 配置文件类型
Config Mysql `json:"config"` // 解析之后的配置文件
}
const (
@ -70,3 +61,39 @@ const (
// FileTypeJson json
FileTypeJson = "json"
)
// Database 数据库配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:19 2022/6/9
type Database struct {
Master *Mysql `json:"master" yaml:"master"`
Slave *Mysql `json:"slave" yaml:"slave"`
}
// Mysql ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:44 2022/5/14
type Mysql struct {
Host string `json:"host" yaml:"host"` // 数据库地址
Port int `json:"port" yaml:"port"` // 数据库端口
Username string `json:"username" yaml:"username"` // 用户名
Password string `json:"password" yaml:"password"` // 密码
Database string `json:"database" yaml:"database"` // 数据库
Charset string `json:"charset" yaml:"charset"` // 数据库编码
Connection *Connection `json:"connection" yaml:"connection"` // 连接配置
LogFileName string `json:"log_file_name" yaml:"log_file_name"` // 日志文件名
}
// Connection 连接数配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:18 2022/6/9
type Connection struct {
MaxOpen int `json:"max_open" yaml:"max_open"` // 最大打开连接数
MaxIdle int `json:"max_idle" yaml:"max_idle"` // 最大的处理连接数
}

2
go.mod
View File

@ -4,7 +4,7 @@ go 1.17
require (
git.zhangdeman.cn/zhangdeman/logger v0.0.0-20220514052229-cf395d3dc4c3
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220514082633-1be4d9eab11f
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220609072516-022a755fdf2f
github.com/gin-gonic/gin v1.7.7
github.com/pkg/errors v0.9.1
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2

2
go.sum
View File

@ -4,6 +4,8 @@ git.zhangdeman.cn/zhangdeman/logger v0.0.0-20220514052229-cf395d3dc4c3 h1:T41tE9
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=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=