summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2014-04-14 14:49:50 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2014-04-14 14:49:50 +0800
commit6cee65db5a6e6ef7372f19d45c22a416e130afed (patch)
treede5cf036622fa6abb5cb356a223a93247122e1aa /models
parent8c266f2df5848b230c6fbb0bc4578a8907edc725 (diff)
downloadgitea-6cee65db5a6e6ef7372f19d45c22a416e130afed.tar.gz
gitea-6cee65db5a6e6ef7372f19d45c22a416e130afed.zip
bug fixed #76
Diffstat (limited to 'models')
-rw-r--r--models/models.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/models/models.go b/models/models.go
index f1d43531be..ab13548ef7 100644
--- a/models/models.go
+++ b/models/models.go
@@ -8,6 +8,7 @@ import (
"fmt"
"os"
"path"
+ "strings"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
@@ -55,8 +56,18 @@ func NewTestEngine(x *xorm.Engine) (err error) {
x, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8",
DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name))
case "postgres":
- x, 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]
+ }
+ cnnstr := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=%s",
+ DbCfg.User, DbCfg.Pwd, host, port, DbCfg.Name, DbCfg.SslMode)
+ //fmt.Println(cnnstr)
+ x, err = xorm.NewEngine("postgres", cnnstr)
case "sqlite3":
if !EnableSQLite3 {
return fmt.Errorf("Unknown database type: %s", DbCfg.Type)