20 Star 165 Fork 26

qiqi / orange

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
db.go 1.66 KB
一键复制 编辑 原始数据 按行查看 历史
qiqi 提交于 2021-09-26 11:05 . 添加gorm原生数据连接驱动
package database
import (
"gitee.com/zhucheer/orange/cfg"
"github.com/zhuCheer/pool"
"regexp"
"strings"
)
type DataBase interface {
RegisterAll()
Register(string)
insertPool(string, pool.Pool)
getDB(string) (interface{}, func(), error)
putDB(string, interface{}) error
}
// RegisterAll 注册所有支持的驱动
func RegisterAll() {
go NewMysql().RegisterAll()
go NewGorm().RegisterAll()
go NewRedis().RegisterAll()
go NewMongo().RegisterAll()
go NewPostgre().RegisterAll()
}
// PutConn 将连接放回连接池方法
func PutConn(put func()) {
if put == nil {
return
}
put()
return
}
func getDBIntConfig(dbtype, name, key string) int {
exists := cfg.Config.Exists("database." + dbtype + "." + name + "." + key)
if exists == false {
return cfg.Config.GetInt("database." + key)
}
return cfg.Config.GetInt("database." + dbtype + "." + name + "." + key)
}
func getBoolConfig(dbtype, name, key string) bool {
exists := cfg.Config.Exists("database." + dbtype + "." + name + "." + key)
if exists == false {
return cfg.Config.GetBool("database." + key)
}
return cfg.Config.GetBool("database." + dbtype + "." + name + "." + key)
}
// 隐藏连接密码日志
func hideDsnPasswordLog(dsn string) (hideDsn string) {
hideDsn = dsn
hideDsnData := regexp.MustCompile(`\/\/[\w]+\:(.*)@`).FindStringSubmatch(dsn)
if len(hideDsnData) > 1 {
hideDsn = strings.Replace(dsn, hideDsnData[1], "******", -1)
}
return
}
func hideTcpDsnPasswordLog(dsn string) (hideDsn string) {
hideDsn = dsn
hideDsnData := regexp.MustCompile(`[\w]+\:(.*)@tcp`).FindStringSubmatch(dsn)
if len(hideDsnData) > 1 {
hideDsn = strings.Replace(dsn, hideDsnData[1], "******", -1)
}
return
}
Go
1
https://gitee.com/zhucheer/orange.git
git@gitee.com:zhucheer/orange.git
zhucheer
orange
orange
v0.5.16

搜索帮助