...
Package hostport
import "cmd/vendor/golang.org/x/tools/go/analysis/passes/hostport"
- Overview
- Index
Package hostport defines an analyzer for calls to net.Dial with
addresses of the form "%s:%d" or "%s:%s", which work only with IPv4.
Constants
const Doc = `check format of addresses passed to net.Dial
This analyzer flags code that produce network address strings using
fmt.Sprintf, as in this example:
addr := fmt.Sprintf("%s:%d", host, 12345) // "will not work with IPv6"
...
conn, err := net.Dial("tcp", addr) // "when passed to dial here"
The analyzer suggests a fix to use the correct approach, a call to
net.JoinHostPort:
addr := net.JoinHostPort(host, "12345")
...
conn, err := net.Dial("tcp", addr)
A similar diagnostic and fix are produced for a format string of "%s:%s".
`
Variables
var Analyzer = &analysis.Analyzer{
Name: "hostport",
Doc: Doc,
URL: "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/hostport",
Requires: []*analysis.Analyzer{inspect.Analyzer, typeindexanalyzer.Analyzer},
Run: run,
}