aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThibault Meyer <0xbaadf00d@users.noreply.github.com>2016-08-12 11:42:06 +0200
committer无闻 <u@gogs.io>2016-08-12 02:42:06 -0700
commit42964272149e2b8f5f3959100c43210cd508e2f5 (patch)
tree32451c9cba804cee1f9138327684dae596ccab8f
parent7551141dbe7bc46be7f448fa65a72ec13f73400b (diff)
downloadgitea-42964272149e2b8f5f3959100c43210cd508e2f5.tar.gz
gitea-42964272149e2b8f5f3959100c43210cd508e2f5.zip
Fix #3437: Cannot connect to PostgreSQL via IPv6 address (#3442)
* Change PostgreSQL connstring parsing to handle IPv6 * Fix used variable * Remove redundant code + use variable
-rw-r--r--models/models.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/models/models.go b/models/models.go
index ace9a2167a..ac69a778e7 100644
--- a/models/models.go
+++ b/models/models.go
@@ -114,12 +114,12 @@ func getEngine() (*xorm.Engine, error) {
}
case "postgres":
host, port := "127.0.0.1", "5432"
- fields := strings.Split(DbCfg.Host, ":")
- if len(fields) > 0 && len(strings.TrimSpace(fields[0])) > 0 {
- host = fields[0]
- }
- if len(fields) > 1 && len(strings.TrimSpace(fields[1])) > 0 {
- port = fields[1]
+ if strings.Contains(DbCfg.Host, ":") && !strings.HasSuffix(DbCfg.Host, "]") {
+ idx := strings.LastIndex(DbCfg.Host, ":")
+ host = DbCfg.Host[:idx]
+ port = DbCfg.Host[idx+1:]
+ } else if len(DbCfg.Host) > 0 {
+ host = DbCfg.Host
}
if host[0] == '/' { // looks like a unix socket