add options , config

This commit is contained in:
Jay
2018-05-08 16:19:51 +08:00
parent 80e5f0b19c
commit fe884e6931
10 changed files with 172 additions and 12 deletions
+5 -1
View File
@@ -2,7 +2,9 @@ package models
import (
"database/sql"
"fmt"
"git.trj.tw/golang/go-gallery/modules/config"
_ "github.com/lib/pq"
)
@@ -11,6 +13,8 @@ var x *sql.DB
// NewDB - db object
func NewDB() (*sql.DB, error) {
var err error
x, err = sql.Open("postgres", "user=postgres host=localhost sslmode=disable dbname=gallery")
conf := config.GetConf()
connStr := fmt.Sprintf("user=%s host=%s sslmode=disable dbname=%s port=%d", conf.Database.User, conf.Database.Host, conf.Database.DBName, conf.Database.Port)
x, err = sql.Open("postgres", connStr)
return x, err
}