Skip to content

Commit

Permalink
chore: compatible zeabur env
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaomaiTX committed Jul 23, 2024
1 parent 0296a45 commit b01ef7a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion connection/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down
14 changes: 13 additions & 1 deletion utils/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 ""
}

0 comments on commit b01ef7a

Please sign in to comment.