diff options
author | Paulo Gomes <pjbgf@linux.com> | 2023-05-11 22:01:31 +0100 |
---|---|---|
committer | Paulo Gomes <pjbgf@linux.com> | 2023-05-11 22:01:31 +0100 |
commit | cb72b58b7576e28627e58338c92e61d3d41a72d7 (patch) | |
tree | 257eed760856561838bb73f20dc1c2f0aee55b2d /plumbing/transport | |
parent | 096b3cc16b547f3c0d6e4f92046945bcfac0fa14 (diff) | |
download | go-git-cb72b58b7576e28627e58338c92e61d3d41a72d7.tar.gz |
*: Replace fmt.Sprintf with net.JoinHostPort
Signed-off-by: Paulo Gomes <pjbgf@linux.com>
Diffstat (limited to 'plumbing/transport')
-rw-r--r-- | plumbing/transport/git/common.go | 5 | ||||
-rw-r--r-- | plumbing/transport/ssh/common.go | 4 |
2 files changed, 5 insertions, 4 deletions
diff --git a/plumbing/transport/git/common.go b/plumbing/transport/git/common.go index c18d600..92fc0be 100644 --- a/plumbing/transport/git/common.go +++ b/plumbing/transport/git/common.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "net" + "strconv" "github.com/go-git/go-git/v5/plumbing/format/pktline" "github.com/go-git/go-git/v5/plumbing/transport" @@ -69,7 +70,7 @@ func (c *command) getHostWithPort() string { port = DefaultPort } - return fmt.Sprintf("%s:%d", host, port) + return net.JoinHostPort(host, strconv.Itoa(port)) } // StderrPipe git protocol doesn't have any dedicated error channel @@ -92,7 +93,7 @@ func (c *command) StdoutPipe() (io.Reader, error) { func endpointToCommand(cmd string, ep *transport.Endpoint) string { host := ep.Host if ep.Port != DefaultPort { - host = fmt.Sprintf("%s:%d", ep.Host, ep.Port) + host = net.JoinHostPort(ep.Host, strconv.Itoa(ep.Port)) } return fmt.Sprintf("%s %s%chost=%s%c", cmd, ep.Path, 0, host, 0) diff --git a/plumbing/transport/ssh/common.go b/plumbing/transport/ssh/common.go index 6617d9b..1531603 100644 --- a/plumbing/transport/ssh/common.go +++ b/plumbing/transport/ssh/common.go @@ -212,7 +212,7 @@ func (c *command) getHostWithPort() string { port = DefaultPort } - return fmt.Sprintf("%s:%d", host, port) + return net.JoinHostPort(host, strconv.Itoa(port)) } func (c *command) doGetHostWithPortFromSSHConfig() (addr string, found bool) { @@ -240,7 +240,7 @@ func (c *command) doGetHostWithPortFromSSHConfig() (addr string, found bool) { } } - addr = fmt.Sprintf("%s:%d", host, port) + addr = net.JoinHostPort(host, strconv.Itoa(port)) return } |