From e610e02d4553264790309d4f14060185703d35d2 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 17:49:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=B9=E9=87=8F=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E9=85=8D=E7=BD=AE=20TODO=20:=20=E5=BE=85=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 4 ++++ define.go | 51 +++++++++++++++++++++++++++++++++++++++------------ go.mod | 2 +- go.sum | 2 ++ 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/client.go b/client.go index 98e4c47..a2190e1 100644 --- a/client.go +++ b/client.go @@ -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 } } diff --git a/define.go b/define.go index b9f5726..3f4af91 100644 --- a/define.go +++ b/define.go @@ -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"` // 最大的处理连接数 +} diff --git a/go.mod b/go.mod index be718ad..8e08cef 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index c3993c8..d6718ad 100644 --- a/go.sum +++ b/go.sum @@ -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=