From ff5824fc3a6b4b2158531c54d69711e67626099d Mon Sep 17 00:00:00 2001 From: Chun-Hung Tseng Date: Sun, 12 May 2024 05:32:08 +0800 Subject: [PATCH] Tidy up net.SplitHostPort MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chun-Hung Tseng Co-authored-by: Iván Valdés Castillo --- pkg/proxy/server.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/proxy/server.go b/pkg/proxy/server.go index 6f0737c27975..890eec4b9b14 100644 --- a/pkg/proxy/server.go +++ b/pkg/proxy/server.go @@ -219,14 +219,11 @@ func NewServer(cfg ServerConfig) Server { pauseRxc: make(chan struct{}), } - _, fromPort, err := net.SplitHostPort(cfg.From.Host) - if err == nil { + if _, fromPort, err := net.SplitHostPort(cfg.From.Host); err == nil { s.fromPort, _ = strconv.Atoi(fromPort) } if !s.isForwardProxy { - var toPort string - _, toPort, err = net.SplitHostPort(cfg.To.Host) - if err == nil { + if _, toPort, err := net.SplitHostPort(cfg.To.Host); err == nil { s.toPort, _ = strconv.Atoi(toPort) } } @@ -260,6 +257,7 @@ func NewServer(cfg ServerConfig) Server { } var ln net.Listener + var err error if !s.tlsInfo.Empty() { ln, err = transport.NewListener(addr, s.from.Scheme, &s.tlsInfo) } else {