抽离配置到nacos里

This commit is contained in:
2026-08-12 16:04:04 +08:00
parent c8372f9b79
commit 92c30163b5
13 changed files with 356 additions and 644 deletions
+8 -7
View File
@@ -7,6 +7,7 @@ import (
"gorm.io/gorm"
"gorm.io/gorm/schema"
"gorm.io/plugin/dbresolver"
"pkg.local/utils"
)
type Config struct {
@@ -59,28 +60,28 @@ func New(c Config) (*gorm.DB, error) {
}
func buildReadDSN(c Config) string {
if c.ReadHost == "" {
return ""
if c.ReadHost == utils.StringEmpty {
return utils.StringEmpty
}
port := c.ReadPort
if port == 0 {
if port == utils.NumberZero {
port = c.Port
}
user := c.ReadUser
if user == "" {
if user == utils.StringEmpty {
user = c.User
}
password := c.ReadPassword
if password == "" {
if password == utils.StringEmpty {
password = c.Password
}
database := c.ReadDatabase
if database == "" {
if database == utils.StringEmpty {
database = c.Database
}
charset := c.Charset
if charset == "" {
if charset == utils.StringEmpty {
charset = "utf8mb4"
}
return buildDSN(user, password, c.ReadHost, port, database, charset)