From ce0291a8f985fe4ffeb6bb305b2cc98e8291bc65 Mon Sep 17 00:00:00 2001 From: Tom <56171752+Flying-Tom@users.noreply.github.com> Date: Wed, 3 Sep 2025 19:43:16 +0800 Subject: [PATCH] feat: add TLS configuration option for MySQL (#384) --- README.md | 1 + README_EN.md | 1 + cmd/apimain.go | 3 ++- conf/config.yaml | 1 + config/gorm.go | 1 + go.mod | 2 +- 6 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8948192..0e69431 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,7 @@ | RUSTDESK_API_MYSQL_PASSWORD | mysql密码 | 111111 | | RUSTDESK_API_MYSQL_ADDR | mysql地址 | 192.168.1.66:3306 | | RUSTDESK_API_MYSQL_DBNAME | mysql数据库名 | rustdesk | +| RUSTDESK_API_MYSQL_TLS | 是否启用TLS, 可选值: `true`, `false`, `skip-verify`, `custom` | `false` | | -----RUSTDESK配置----- | ---------- | ---------- | | RUSTDESK_API_RUSTDESK_ID_SERVER | Rustdesk的id服务器地址 | 192.168.1.66:21116 | | RUSTDESK_API_RUSTDESK_RELAY_SERVER | Rustdesk的relay服务器地址 | 192.168.1.66:21117 | diff --git a/README_EN.md b/README_EN.md index f2d2687..96687c6 100644 --- a/README_EN.md +++ b/README_EN.md @@ -188,6 +188,7 @@ The table below does not list all configurations. Please refer to the configurat | RUSTDESK_API_MYSQL_PASSWORD | MySQL password | 111111 | | RUSTDESK_API_MYSQL_ADDR | MySQL address | 192.168.1.66:3306 | | RUSTDESK_API_MYSQL_DBNAME | MySQL database name | rustdesk | +| RUSTDESK_API_MYSQL_TLS | Whether to enable TLS, optional values: `true`, `false`, `skip-verify`, `custom` | `false` | | ----- RUSTDESK Configuration ----- | --------------------------------------- | ----------------------------- | | RUSTDESK_API_RUSTDESK_ID_SERVER | Rustdesk ID server address | 192.168.1.66:21116 | | RUSTDESK_API_RUSTDESK_RELAY_SERVER | Rustdesk relay server address | 192.168.1.66:21117 | diff --git a/cmd/apimain.go b/cmd/apimain.go index 31c9d1d..eddefb2 100644 --- a/cmd/apimain.go +++ b/cmd/apimain.go @@ -145,11 +145,12 @@ func InitGlobal() { //gorm if global.Config.Gorm.Type == config.TypeMysql { - dsn := fmt.Sprintf("%s:%s@(%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", + dsn := fmt.Sprintf("%s:%s@(%s)/%s?charset=utf8mb4&parseTime=True&loc=Local&tls=%s", global.Config.Mysql.Username, global.Config.Mysql.Password, global.Config.Mysql.Addr, global.Config.Mysql.Dbname, + global.Config.Mysql.Tls, ) global.DB = orm.NewMysql(&orm.MysqlConfig{ diff --git a/conf/config.yaml b/conf/config.yaml index 7d9df21..91162b7 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -31,6 +31,7 @@ mysql: password: "" addr: "" dbname: "" + tls: "false" # true / false / skip-verify / custom postgresql: host: "127.0.0.1" diff --git a/config/gorm.go b/config/gorm.go index 8c666a3..04c2f98 100644 --- a/config/gorm.go +++ b/config/gorm.go @@ -17,6 +17,7 @@ type Mysql struct { Username string `mapstructure:"username"` Password string `mapstructure:"password"` Dbname string `mapstructure:"dbname"` + Tls string `mapstructure:"tls"` // true / false / skip-verify / custom } type Postgresql struct { diff --git a/go.mod b/go.mod index 2759a4d..017f912 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,7 @@ require ( github.com/swaggo/files v1.0.1 github.com/swaggo/gin-swagger v1.6.0 github.com/swaggo/swag v1.16.3 + golang.org/x/crypto v0.33.0 golang.org/x/oauth2 v0.23.0 golang.org/x/text v0.22.0 gorm.io/driver/mysql v1.5.7 @@ -84,7 +85,6 @@ require ( github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.9 // indirect golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect - golang.org/x/crypto v0.33.0 // indirect golang.org/x/image v0.13.0 // indirect golang.org/x/net v0.34.0 // indirect golang.org/x/sync v0.11.0 // indirect