Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FLIPPED-AURORA
gin-vue-admin
提交
fba9f412
G
gin-vue-admin
项目概览
FLIPPED-AURORA
/
gin-vue-admin
10 个月 前同步成功
通知
324
Star
18154
Fork
5505
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
fba9f412
编写于
5月 23, 2022
作者:
Sliver_Horn
提交者:
GitHub
5月 23, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1081 from pnck/main
fix: 修复多库模式不能使用 pg 的问题
上级
118f9b08
bf72d4f3
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
47 addition
and
52 deletion
+47
-52
server/config/config.go
server/config/config.go
+3
-3
server/config/db_list.go
server/config/db_list.go
+15
-7
server/config/gorm_mysql.go
server/config/gorm_mysql.go
+1
-10
server/config/gorm_pgsql.go
server/config/gorm_pgsql.go
+1
-10
server/initialize/db_list.go
server/initialize/db_list.go
+3
-2
server/initialize/gorm_mysql.go
server/initialize/gorm_mysql.go
+1
-1
server/initialize/gorm_pgsql.go
server/initialize/gorm_pgsql.go
+1
-1
server/model/system/request/sys_init.go
server/model/system/request/sys_init.go
+22
-18
未找到文件。
server/config/config.go
浏览文件 @
fba9f412
...
...
@@ -11,9 +11,9 @@ type Server struct {
// auto
AutoCode
Autocode
`mapstructure:"autocode" json:"autocode" yaml:"autocode"`
// gorm
Mysql
Mysql
`mapstructure:"mysql" json:"mysql" yaml:"mysql"`
Pgsql
Pgsql
`mapstructure:"pgsql" json:"pgsql" yaml:"pgsql"`
DBList
[]
DB
`mapstructure:"db-list" json:"db-list" yaml:"db-list"`
Mysql
Mysql
`mapstructure:"mysql" json:"mysql" yaml:"mysql"`
Pgsql
Pgsql
`mapstructure:"pgsql" json:"pgsql" yaml:"pgsql"`
DBList
[]
SpecializedDB
`mapstructure:"db-list" json:"db-list" yaml:"db-list"`
// oss
Local
Local
`mapstructure:"local" json:"local" yaml:"local"`
Qiniu
Qiniu
`mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
...
...
server/config/db_list.go
浏览文件 @
fba9f412
package
config
type
DB
struct
{
Disable
bool
`mapstructure:"disable" json:"disable" yaml:"disable"`
Type
string
`mapstructure:"type" json:"type" yaml:"type"`
AliasName
string
`mapstructure:"alias-name" json:"alias-name" yaml:"alias-name"`
type
DsnProvider
interface
{
Dsn
()
string
}
// Embeded 结构体可以压平到上一层,从而保持 config 文件的结构和原来一样
// 见 playground: https://go.dev/play/p/KIcuhqEoxmY
// GeneralDB 也被 Pgsql 和 Mysql 原样使用
type
GeneralDB
struct
{
Path
string
`mapstructure:"path" json:"path" yaml:"path"`
// 服务器地址:端口
Port
string
`mapstructure:"port" json:"port" yaml:"port"`
//:端口
Config
string
`mapstructure:"config" json:"config" yaml:"config"`
// 高级配置
...
...
@@ -13,9 +18,12 @@ type DB struct {
MaxIdleConns
int
`mapstructure:"max-idle-conns" json:"max-idle-conns" yaml:"max-idle-conns"`
// 空闲中的最大连接数
MaxOpenConns
int
`mapstructure:"max-open-conns" json:"max-open-conns" yaml:"max-open-conns"`
// 打开到数据库的最大连接数
LogMode
string
`mapstructure:"log-mode" json:"log-mode" yaml:"log-mode"`
// 是否开启Gorm全局日志
LogZap
bool
`mapstructure:"log-zap" json:"log-zap" yaml:"log-zap"`
LogZap
bool
`mapstructure:"log-zap" json:"log-zap" yaml:"log-zap"`
// 是否通过zap写入日志文件
}
func
(
m
*
DB
)
Dsn
()
string
{
return
m
.
Username
+
":"
+
m
.
Password
+
"@tcp("
+
m
.
Path
+
":"
+
m
.
Port
+
")/"
+
m
.
Dbname
+
"?"
+
m
.
Config
type
SpecializedDB
struct
{
Disable
bool
`mapstructure:"disable" json:"disable" yaml:"disable"`
Type
string
`mapstructure:"type" json:"type" yaml:"type"`
AliasName
string
`mapstructure:"alias-name" json:"alias-name" yaml:"alias-name"`
GeneralDB
`yaml:",inline" mapstructure:",squash"`
}
server/config/gorm_mysql.go
浏览文件 @
fba9f412
package
config
type
Mysql
struct
{
Path
string
`mapstructure:"path" json:"path" yaml:"path"`
// 服务器地址
Port
string
`mapstructure:"port" json:"port" yaml:"port"`
// 端口
Config
string
`mapstructure:"config" json:"config" yaml:"config"`
// 高级配置
Dbname
string
`mapstructure:"db-name" json:"db-name" yaml:"db-name"`
// 数据库名
Username
string
`mapstructure:"username" json:"username" yaml:"username"`
// 数据库用户名
Password
string
`mapstructure:"password" json:"password" yaml:"password"`
// 数据库密码
MaxIdleConns
int
`mapstructure:"max-idle-conns" json:"max-idle-conns" yaml:"max-idle-conns"`
// 空闲中的最大连接数
MaxOpenConns
int
`mapstructure:"max-open-conns" json:"max-open-conns" yaml:"max-open-conns"`
// 打开到数据库的最大连接数
LogMode
string
`mapstructure:"log-mode" json:"log-mode" yaml:"log-mode"`
// 是否开启Gorm全局日志
LogZap
bool
`mapstructure:"log-zap" json:"log-zap" yaml:"log-zap"`
// 是否通过zap写入日志文件
GeneralDB
`yaml:",inline" mapstructure:",squash"`
}
func
(
m
*
Mysql
)
Dsn
()
string
{
...
...
server/config/gorm_pgsql.go
浏览文件 @
fba9f412
package
config
type
Pgsql
struct
{
Path
string
`mapstructure:"path" json:"path" yaml:"path"`
// 服务器地址:端口
Port
string
`mapstructure:"port" json:"port" yaml:"port"`
//:端口
Config
string
`mapstructure:"config" json:"config" yaml:"config"`
// 高级配置
Dbname
string
`mapstructure:"db-name" json:"db-name" yaml:"db-name"`
// 数据库名
Username
string
`mapstructure:"username" json:"username" yaml:"username"`
// 数据库用户名
Password
string
`mapstructure:"password" json:"password" yaml:"password"`
// 数据库密码
MaxIdleConns
int
`mapstructure:"max-idle-conns" json:"max-idle-conns" yaml:"max-idle-conns"`
// 空闲中的最大连接数
MaxOpenConns
int
`mapstructure:"max-open-conns" json:"max-open-conns" yaml:"max-open-conns"`
// 打开到数据库的最大连接数
LogMode
string
`mapstructure:"log-mode" json:"log-mode" yaml:"log-mode"`
// 是否开启Gorm全局日志
LogZap
bool
`mapstructure:"log-zap" json:"log-zap" yaml:"log-zap"`
// 是否通过zap写入日志文件
GeneralDB
`yaml:",inline" mapstructure:",squash"`
}
// Dsn 基于配置文件获取 dsn
...
...
server/initialize/db_list.go
浏览文件 @
fba9f412
package
initialize
import
(
"github.com/flipped-aurora/gin-vue-admin/server/config"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"gorm.io/gorm"
)
...
...
@@ -15,9 +16,9 @@ func DBList() {
}
switch
info
.
Type
{
case
"mysql"
:
dbMap
[
info
.
Dbname
]
=
GormMysqlByConfig
(
info
)
dbMap
[
info
.
GeneralDB
.
Dbname
]
=
GormMysqlByConfig
(
config
.
Mysql
{
GeneralDB
:
info
.
GeneralDB
}
)
case
"pgsql"
:
dbMap
[
info
.
Dbname
]
=
GormPgSqlByConfig
(
info
)
dbMap
[
info
.
GeneralDB
.
Dbname
]
=
GormPgSqlByConfig
(
config
.
Pgsql
{
GeneralDB
:
info
.
GeneralDB
}
)
default
:
continue
}
...
...
server/initialize/gorm_mysql.go
浏览文件 @
fba9f412
...
...
@@ -32,7 +32,7 @@ func GormMysql() *gorm.DB {
}
// GormMysqlByConfig 初始化Mysql数据库用过传入配置
func
GormMysqlByConfig
(
m
config
.
DB
)
*
gorm
.
DB
{
func
GormMysqlByConfig
(
m
config
.
Mysql
)
*
gorm
.
DB
{
if
m
.
Dbname
==
""
{
return
nil
}
...
...
server/initialize/gorm_pgsql.go
浏览文件 @
fba9f412
...
...
@@ -31,7 +31,7 @@ func GormPgSql() *gorm.DB {
}
// GormPgSqlByConfig 初始化 Postgresql 数据库 通过参数
func
GormPgSqlByConfig
(
p
config
.
DB
)
*
gorm
.
DB
{
func
GormPgSqlByConfig
(
p
config
.
Pgsql
)
*
gorm
.
DB
{
if
p
.
Dbname
==
""
{
return
nil
}
...
...
server/model/system/request/sys_init.go
浏览文件 @
fba9f412
...
...
@@ -43,15 +43,17 @@ func (i *InitDB) PgsqlEmptyDsn() string {
// Author [SliverHorn](https://github.com/SliverHorn)
func
(
i
*
InitDB
)
ToMysqlConfig
()
config
.
Mysql
{
return
config
.
Mysql
{
Path
:
i
.
Host
,
Port
:
i
.
Port
,
Dbname
:
i
.
DBName
,
Username
:
i
.
UserName
,
Password
:
i
.
Password
,
MaxIdleConns
:
10
,
MaxOpenConns
:
100
,
LogMode
:
"error"
,
Config
:
"charset=utf8mb4&parseTime=True&loc=Local"
,
GeneralDB
:
config
.
GeneralDB
{
Path
:
i
.
Host
,
Port
:
i
.
Port
,
Dbname
:
i
.
DBName
,
Username
:
i
.
UserName
,
Password
:
i
.
Password
,
MaxIdleConns
:
10
,
MaxOpenConns
:
100
,
LogMode
:
"error"
,
Config
:
"charset=utf8mb4&parseTime=True&loc=Local"
,
},
}
}
...
...
@@ -59,14 +61,16 @@ func (i *InitDB) ToMysqlConfig() config.Mysql {
// Author [SliverHorn](https://github.com/SliverHorn)
func
(
i
*
InitDB
)
ToPgsqlConfig
()
config
.
Pgsql
{
return
config
.
Pgsql
{
Path
:
i
.
Host
,
Port
:
i
.
Port
,
Dbname
:
i
.
DBName
,
Username
:
i
.
UserName
,
Password
:
i
.
Password
,
MaxIdleConns
:
10
,
MaxOpenConns
:
100
,
LogMode
:
"error"
,
Config
:
"sslmode=disable TimeZone=Asia/Shanghai"
,
GeneralDB
:
config
.
GeneralDB
{
Path
:
i
.
Host
,
Port
:
i
.
Port
,
Dbname
:
i
.
DBName
,
Username
:
i
.
UserName
,
Password
:
i
.
Password
,
MaxIdleConns
:
10
,
MaxOpenConns
:
100
,
LogMode
:
"error"
,
Config
:
"sslmode=disable TimeZone=Asia/Shanghai"
,
},
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录