Using net.JoinHostPort instead of handcrafting addrs

This commit is contained in:
Diptanu Choudhury 2016-07-08 16:31:54 -07:00
parent b180223f4b
commit 48b9684b1e
2 changed files with 10 additions and 2 deletions

View File

@ -27,7 +27,9 @@ package consul
import (
"fmt"
"log"
"net"
"net/url"
"strconv"
"strings"
"sync"
"time"
@ -703,12 +705,12 @@ func (c *Syncer) createCheckReg(check *structs.ServiceCheck, serviceReg *consul.
}
url := url.URL{
Scheme: check.Protocol,
Host: fmt.Sprintf("%s:%d", host, port),
Host: net.JoinHostPort(host, strconv.Itoa(port)),
Path: check.Path,
}
chkReg.HTTP = url.String()
case structs.ServiceCheckTCP:
chkReg.TCP = fmt.Sprintf("%s:%d", host, port)
chkReg.TCP = net.JoinHostPort(host, strconv.Itoa(port))
case structs.ServiceCheckScript:
chkReg.TTL = (check.Interval + ttlCheckBuffer).String()
default:

View File

@ -2781,6 +2781,12 @@ func TestTaskDiff(t *testing.T) {
Old: "foo",
New: "foo",
},
{
Type: DiffTypeNone,
Name: "PortLabel",
Old: "",
New: "",
},
{
Type: DiffTypeNone,
Name: "Protocol",