Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
efb15205
Unverified
Commit
efb15205
authored
Nov 20, 2018
by
Stephan Renatus
Committed by
GitHub
Nov 20, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1352 from concourse/pr/support-pq-host-port
pg: support host:port for backwards-compatibility
parents
d4004380
0b856d1a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
4 deletions
+24
-4
config.go
storage/sql/config.go
+17
-4
config_test.go
storage/sql/config_test.go
+7
-0
No files found.
storage/sql/config.go
View file @
efb15205
...
...
@@ -3,6 +3,7 @@ package sql
import
(
"database/sql"
"fmt"
"net"
"regexp"
"strconv"
"strings"
...
...
@@ -116,12 +117,24 @@ func (p *Postgres) createDataSourceName() string {
addParam
(
"connect_timeout"
,
strconv
.
Itoa
(
p
.
ConnectionTimeout
))
if
p
.
Host
!=
""
{
addParam
(
"host"
,
dataSourceStr
(
p
.
Host
))
}
// detect host:port for backwards-compatibility
host
,
port
,
err
:=
net
.
SplitHostPort
(
p
.
Host
)
if
err
!=
nil
{
// not host:port, probably unix socket or bare address
host
=
p
.
Host
if
p
.
Port
!=
0
{
addParam
(
"port"
,
strconv
.
Itoa
(
int
(
p
.
Port
)))
port
=
strconv
.
Itoa
(
int
(
p
.
Port
))
}
}
if
host
!=
""
{
addParam
(
"host"
,
dataSourceStr
(
host
))
}
if
port
!=
""
{
addParam
(
"port"
,
port
)
}
if
p
.
User
!=
""
{
...
...
storage/sql/config_test.go
View file @
efb15205
...
...
@@ -119,6 +119,13 @@ func TestCreateDataSourceName(t *testing.T) {
},
expected
:
"connect_timeout=0 host='coreos.com' sslmode='disable'"
,
},
{
description
:
"with tcp host:port"
,
input
:
&
Postgres
{
Host
:
"coreos.com:6543"
,
},
expected
:
"connect_timeout=0 host='coreos.com' port=6543 sslmode='verify-full'"
,
},
{
description
:
"with tcp host and port"
,
input
:
&
Postgres
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment