Skip to content

Commit ade935f

Browse files
author
Justin Fudally
authored
Merge pull request #115 from github/jfudally-fix-address-parse
Fix HAProxy address parse
2 parents 93523b2 + ac14e0d commit ade935f

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ bin/
33
main
44
conf/freno.local.conf.json
55
.vendor/
6+
.idea/

go/config/haproxy_config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ func (h *HostPort) URL() *url.URL {
2727
}
2828

2929
func ParseHostPort(address string) (hostPort *HostPort, err error) {
30+
if !strings.Contains(address, ":") {
31+
if address == "" {
32+
return &HostPort{address, 80}, fmt.Errorf("Invalid host address: %s", address)
33+
}
34+
35+
return &HostPort{Host: address, Port: 80}, nil
36+
}
37+
3038
tokens := strings.SplitN(address, ":", 2)
3139
if len(tokens) != 2 {
3240
return nil, fmt.Errorf("Cannot parse HostPort from %s. Expected format is host:port", address)

go/config/haproxy_config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestParseAddresses(t *testing.T) {
7171
{
7272
c := &HAProxyConfigurationSettings{Addresses: "localhost"}
7373
_, err := c.parseAddresses()
74-
test.S(t).ExpectNotNil(err)
74+
test.S(t).ExpectNil(err)
7575
}
7676
{
7777
c := &HAProxyConfigurationSettings{Addresses: "localhost:"}

0 commit comments

Comments
 (0)