change connStr format

This commit is contained in:
Jay 2018-09-20 22:35:18 +08:00
parent 0e0d2b94b6
commit 386a24affb

View File

@ -15,7 +15,12 @@ var x *sqlx.DB
func NewDB() (*sqlx.DB, error) { func NewDB() (*sqlx.DB, error) {
var err error var err error
conf := config.GetConf() conf := config.GetConf()
connStr := fmt.Sprintf("user=%s password=%s host=%s sslmode=disable dbname=%s port=%d", conf.Database.User, conf.Database.Pass, conf.Database.Host, conf.Database.DB, conf.Database.Port) userPassStr := conf.Database.User
if len(conf.Database.Pass) > 0 {
userPassStr += ":" + conf.Database.Pass
}
connStr := fmt.Sprintf("postgres://%s@%s/%s?sslmode=disable", userPassStr, conf.Database.Host, conf.Database.DB)
// connStr := fmt.Sprintf("user=%s password=%s host=%s sslmode=disable dbname=%s port=%d", conf.Database.User, conf.Database.Pass, conf.Database.Host, conf.Database.DB, conf.Database.Port)
x, err = sqlx.Connect("postgres", connStr) x, err = sqlx.Connect("postgres", connStr)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)