From fa88e89c974f38f795033d091c34a6132af03395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sun, 5 Jun 2022 16:25:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=BE=E7=BD=AE=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index 43ad8f3..225e96a 100644 --- a/client.go +++ b/client.go @@ -22,6 +22,15 @@ import ( "gorm.io/gorm" ) +// BatchNewDBClient 批量设置数据库实例, 读取指定目录下的yaml文件, 文件名作为标识, 内容是数据库具体配置 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 15:43 2022/6/5 +func BatchNewDBClient(dbConfigDir string) { + +} + // NewDBClient ... // // Author : go_developer@163.com<白茶清欢> @@ -51,10 +60,20 @@ func NewDBClient(masterConf *DBConfig, slaveConf *DBConfig, logConf *LogConfig, // // Date : 3:09 PM 2021/12/24 type DBClient struct { - loggerInstance *zap.Logger - master *gorm.DB - slave *gorm.DB - extraFieldList []string + dbFlag string // 数据库标识 + loggerInstance *zap.Logger // 日志实例 + master *gorm.DB // 主库 + slave *gorm.DB // 从库 + extraFieldList []string // 提取的字段 +} + +// SetFlag 设置数据库标识 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 16:18 2022/6/5 +func (dc *DBClient) SetFlag(dbFlag string) { + dc.dbFlag = dbFlag } // GetMaster 获取主库连接