net.JoinHostPort
instead of fmt.Sprintf(...)
GO-S102713)
14
15func (p *Provider) Proxy(host string, port int, rw io.ReadWriter, opts structs.ProxyOptions) error {
16 cn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", host, port), 3*time.Second)17 if err != nil {
18 return errors.WithStack(err)
19 }
83func (p *apiProxy) ListenAndServe(addr string, port int) error {
84 s := http.Server{Handler: p.handler}
85
86 ln, err := net.Listen("tcp", fmt.Sprintf("%s:%d", addr, port)) 87 if err != nil {
88 return fmt.Errorf("error: could not create kubernetes proxy listener: %v", err)
89 }
Instead of manually joining hostname and port combinations, it is better to use net.JoinHostPort
.
fmt.Sprintf("%s:%s", host, port)
fmt.Sprintf("%s:%d", host, port)
fmt.Sprintf("%s:%s", "", host)
fmt.Sprintf("%s:%d", "", host)
net.JoinHostPort(host, port)
net.JoinHostPort(host, port)
net.JoinHostPort(host, "")
net.JoinHostPort(host, "")