Skip to content

Commit

Permalink
handle ports specified as numbers rather than strings
Browse files Browse the repository at this point in the history
  • Loading branch information
afeld authored and jmcarp committed Jan 15, 2017
1 parent a207bdc commit abda9e3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions models/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ type credentialsJSON struct {
Pass string `json:"pass"`
///////////////////////////////////////////////////

Port string `json:"port"`
// can be an integer or a string
// http://igorsobreira.com/2015/04/11/decoding-json-numbers-into-strings-in-go.html
Port json.Number `json:"port"`
}

func (c credentialsJSON) GetDBName() string {
Expand Down Expand Up @@ -80,7 +82,7 @@ func (c credentialsJSON) GetPassword() string {
}

func (c credentialsJSON) GetPort() string {
return c.Port
return c.Port.String()
}

func CredentialsFromJSON(body string) (creds Credentials, err error) {
Expand Down
14 changes: 14 additions & 0 deletions models/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ func TestCredentialsFromJSON(t *testing.T) {
"user",
"pass",
},
{
`{
"host_name": "host.com",
"port": 5432,
"name": "name",
"user_name": "user",
"password": "pass"
}`,
"host.com",
"5432",
"name",
"user",
"pass",
},
}

for _, test := range tests {
Expand Down

0 comments on commit abda9e3

Please sign in to comment.