Browse Source
Merge pull request #286 from hanyue2020/main
feat: DBConf增加DB配置
pull/287/head
yedf2
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
3 additions and
2 deletions
-
dtmcli/dtmimp/types.go
-
dtmcli/dtmimp/utils.go
|
|
|
@ -21,4 +21,5 @@ type DBConf struct { |
|
|
|
Port int64 `yaml:"Port"` |
|
|
|
User string `yaml:"User"` |
|
|
|
Password string `yaml:"Password"` |
|
|
|
Db string `yaml:"Db"` |
|
|
|
} |
|
|
|
|
|
|
|
@ -210,9 +210,9 @@ func GetDsn(conf DBConf) string { |
|
|
|
driver := conf.Driver |
|
|
|
dsn := map[string]string{ |
|
|
|
"mysql": fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=true&loc=Local&interpolateParams=true", |
|
|
|
conf.User, conf.Password, host, conf.Port, ""), |
|
|
|
conf.User, conf.Password, host, conf.Port, conf.Db), |
|
|
|
"postgres": fmt.Sprintf("host=%s user=%s password=%s dbname='%s' port=%d sslmode=disable", |
|
|
|
host, conf.User, conf.Password, "", conf.Port), |
|
|
|
host, conf.User, conf.Password, conf.Db, conf.Port), |
|
|
|
}[driver] |
|
|
|
PanicIf(dsn == "", fmt.Errorf("unknow driver: %s", driver)) |
|
|
|
return dsn |
|
|
|
|