Skip to content

Commit a4a240e

Browse files
authored
[feat]: config for TLS connection in init MySQL (flipped-aurora#1388)
1 parent b6146d7 commit a4a240e

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

server/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ mysql:
6969
max-open-conns: 100
7070
log-mode: ""
7171
log-zap: false
72+
init-tls: false
7273

7374
# pgsql connect configuration
7475
# 未初始化之前请勿手动修改数据库信息!!!如果一定要手动初始化请看(https://gin-vue-admin.com/docs/first_master)

server/config/db_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type GeneralDB struct {
2222
MaxOpenConns int `mapstructure:"max-open-conns" json:"max-open-conns" yaml:"max-open-conns"` // 打开到数据库的最大连接数
2323
LogMode string `mapstructure:"log-mode" json:"log-mode" yaml:"log-mode"` // 是否开启Gorm全局日志
2424
LogZap bool `mapstructure:"log-zap" json:"log-zap" yaml:"log-zap"` // 是否通过zap写入日志文件
25+
InitTls bool `mapstructure:"init-tls" json:"init-tls" yaml:"init-tls"` // 初始化时是否开启TLS
2526
}
2627

2728
type SpecializedDB struct {

server/model/system/request/sys_init.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ type InitDB struct {
1818
// MysqlEmptyDsn msyql 空数据库 建库链接
1919
// Author SliverHorn
2020
func (i *InitDB) MysqlEmptyDsn() string {
21+
initTls := ""
22+
if config.GeneralDB.InitTls {
23+
initTls = "?tls=true"
24+
}
2125
if i.Host == "" {
2226
i.Host = "127.0.0.1"
2327
}
2428
if i.Port == "" {
2529
i.Port = "3306"
2630
}
27-
return fmt.Sprintf("%s:%s@tcp(%s:%s)/", i.UserName, i.Password, i.Host, i.Port)
31+
return fmt.Sprintf("%s:%s@tcp(%s:%s)/"+initTls, i.UserName, i.Password, i.Host, i.Port)
2832
}
2933

3034
// PgsqlEmptyDsn pgsql 空数据库 建库链接
@@ -42,6 +46,10 @@ func (i *InitDB) PgsqlEmptyDsn() string {
4246
// ToMysqlConfig 转换 config.Mysql
4347
// Author [SliverHorn](https://github.com/SliverHorn)
4448
func (i *InitDB) ToMysqlConfig() config.Mysql {
49+
initTls := ""
50+
if config.GeneralDB.InitTls {
51+
initTls = "&tls=true"
52+
}
4553
return config.Mysql{
4654
GeneralDB: config.GeneralDB{
4755
Path: i.Host,
@@ -52,7 +60,7 @@ func (i *InitDB) ToMysqlConfig() config.Mysql {
5260
MaxIdleConns: 10,
5361
MaxOpenConns: 100,
5462
LogMode: "error",
55-
Config: "charset=utf8mb4&parseTime=True&loc=Local",
63+
Config: "charset=utf8mb4&parseTime=True&loc=Local" + initTls,
5664
},
5765
}
5866
}

0 commit comments

Comments
 (0)