summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorChristopher Brickley <brickley@gmail.com>2014-04-14 21:07:21 -0400
committerChristopher Brickley <brickley@gmail.com>2014-04-14 21:07:21 -0400
commitcaeddb79a339d8eaff78ac0212ac2959700d77de (patch)
tree191c439ece742649fb8dd6f325d7aa4d8eb7ce02 /models
parent337eef2ee57707f055042db21b7b4159db0f0200 (diff)
downloadgitea-caeddb79a339d8eaff78ac0212ac2959700d77de.tar.gz
gitea-caeddb79a339d8eaff78ac0212ac2959700d77de.zip
update SetEngine for postgresql #76
Diffstat (limited to 'models')
-rw-r--r--models/models.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/models/models.go b/models/models.go
index cd9dc38ac1..fe17229cc3 100644
--- a/models/models.go
+++ b/models/models.go
@@ -89,8 +89,16 @@ func SetEngine() (err error) {
orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8",
DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name))
case "postgres":
- orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s",
- DbCfg.User, DbCfg.Pwd, DbCfg.Name, DbCfg.SslMode))
+ var host, port = "127.0.0.1", "5432"
+ fields := strings.Split(DbCfg.Host, ":")
+ if len(fields) > 0 {
+ host = fields[0]
+ }
+ if len(fields) > 1 {
+ port = fields[1]
+ }
+ orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=%s",
+ DbCfg.User, DbCfg.Pwd, host, port, DbCfg.Name, DbCfg.SslMode))
case "sqlite3":
os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm)
orm, err = xorm.NewEngine("sqlite3", DbCfg.Path)