Documentation
¶
Overview ¶
Package netutil provides utility functions for networking, including parsing IP addresses and prefixes.
Index ¶
- func EnsureHostPort(addr, port string) string
- func HTTPServerAddr(addrPort netip.AddrPort) string
- func ParseAddrDefaultPort(addr, defaultPort string) (netip.AddrPort, error)
- func ParseAddrIgnoringPort(addr string) (netip.Addr, error)
- func ParseAddrOrPrefix(addr string) (netip.Prefix, error)
- func Resolve(addr string) stringdeprecated
- func ResolveAll(addr string) ([]net.IP, error)
- func ResolveFirst(addr string) (string, error)
- func TrimIPv6(addr string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureHostPort ¶
EnsureHostPort returns addr that is guaranteed to have a port. If addr already has a port, it is returned unchanged. If addr does not have a port, the supplied port is appended. If addr is an IPv6 address, it will be enclosed in brackets if it is not already.
func HTTPServerAddr ¶
HTTPServerAddr returns the address of an HTTP server based on the address and port of the server in a form to be used with http.Server.Addr. If the address is unspecified then it will be replaced with an empty string. If the port is 80 then "http" will be appended to the address, if the port is 443 then "https" will be appended to the address, otherwise the numeric port will be used.
func ParseAddrDefaultPort ¶
ParseAddrDefaultPort parses an IP address string. If the address string already contains a port, it is parsed and returned. Otherwise, the supplied default port is used to construct and parse an address with that port. If the address contains only a port an address of "::" is used. ParseAddrDefaultPort calls ResolveFirst to resolve the address before parsing it.