From b01ef7a9b26601497047fe651813cb5e08b35fb1 Mon Sep 17 00:00:00 2001 From: XiaomaiTX Date: Tue, 23 Jul 2024 17:37:06 +0800 Subject: [PATCH] chore: compatible zeabur env --- connection/database.go | 3 ++- utils/base.go | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/connection/database.go b/connection/database.go index 8d0fe781..55ddedbe 100644 --- a/connection/database.go +++ b/connection/database.go @@ -6,6 +6,7 @@ import ( "crypto/tls" "database/sql" "fmt" + "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql" _ "github.com/mattn/go-sqlite3" @@ -40,7 +41,7 @@ func getConn() *sql.DB { viper.GetString("mysql.password"), viper.GetString("mysql.host"), viper.GetInt("mysql.port"), - viper.GetString("mysql.db"), + utils.GetStringConfs("mysql.db", "mysql.database"), ) if viper.GetBool("mysql.tls") { mysql.RegisterTLSConfig("tls", &tls.Config{ diff --git a/utils/base.go b/utils/base.go index 2d60b88c..caf3b5b1 100644 --- a/utils/base.go +++ b/utils/base.go @@ -2,9 +2,11 @@ package utils import ( "fmt" - "github.com/goccy/go-json" "math/rand" "time" + + "github.com/goccy/go-json" + "github.com/spf13/viper" ) func Intn(n int) int { @@ -332,3 +334,13 @@ func Range(start int, end int) []int { } return res } + +func GetStringConfs(key ...string) string { + for _, k := range key { + if v := viper.GetString(k); len(v) > 0 { + return v + } + } + + return "" +} \ No newline at end of file