抽离配置到nacos里
This commit is contained in:
+8
-7
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user