diff --git a/model/model.go b/model/model.go index 40295ef..b811d0e 100644 --- a/model/model.go +++ b/model/model.go @@ -15,7 +15,12 @@ var x *sqlx.DB func NewDB() (*sqlx.DB, error) { var err error 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) if err != nil { log.Fatal(err)