Skip to content

Commit 8fafcd9

Browse files
committed
use net.JoinHostPort to support IPv6 correctly
1 parent d43e32c commit 8fafcd9

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

pkg/connectivity/probe/job.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"github.com/mattfenwick/cyclonus/pkg/matcher"
66
"github.com/pkg/errors"
77
v1 "k8s.io/api/core/v1"
8+
"net"
9+
"strconv"
810
)
911

1012
type Jobs struct {
@@ -51,7 +53,7 @@ func (j *Job) Key() string {
5153
}
5254

5355
func (j *Job) ToAddress() string {
54-
return fmt.Sprintf("%s:%d", j.ToHost, j.ResolvedPort)
56+
return net.JoinHostPort(j.ToHost, strconv.Itoa(j.ResolvedPort))
5557
}
5658

5759
func (j *Job) ClientCommand() []string {

pkg/worker/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func NewDefaultClient(host string) *Client {
5151
5252
func NewClient(host string, port int) *Client {
5353
return &Client{Resty: resty.New().
54-
SetHostURL(fmt.Sprintf("%s:%d", host, port)).
54+
SetHostURL(net.JoinHostPort(host, strconv.Itoa(port))).
5555
//SetDebug(false).
5656
SetTimeout(30 * time.Second)}
5757
}

pkg/worker/model.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"fmt"
55
"github.com/pkg/errors"
66
v1 "k8s.io/api/core/v1"
7+
"net"
8+
"strconv"
79
)
810

911
type Batch struct {
@@ -44,7 +46,7 @@ type Request struct {
4446
}
4547

4648
func (r *Request) Address() string {
47-
return fmt.Sprintf("%s:%d", r.Host, r.Port)
49+
return net.JoinHostPort(r.Host, strconv.Itoa(r.Port))
4850
}
4951

5052
func (r *Request) Command() []string {

0 commit comments

Comments
 (0)