Documentation
¶
Index ¶
- Constants
- func AssignRandPort(ip ...string) (int, error)
- func ExternalIP() (string, error)deprecated
- func ExtractIP(addr net.Addr) (ip string, err error)
- func ExtractPort(addr net.Addr) (int, error)
- func FulfillAddr(addr string) string
- func InternalIP() (string, error)deprecated
- func ListenNetwork(network, addr string) string
- func ParseAddr(addr string, expose ...bool) (string, string, error)
- func ParseHostPort(endpoint string) (string, uint64, error)
- func PrivateIP() (string, error)
- func PublicIP() (string, error)
- func SetPrivateIPResolver(resolver IPResolver)
- func SetPublicIPResolver(resolver IPResolver)
- type IPResolver
Constants ¶
const ( IPv4Zero = "0.0.0.0" IPv4Loopback = "127.0.0.1" IPv6Zero = "::" )
Variables ¶
This section is empty.
Functions ¶
func AssignRandPort ¶
AssignRandPort assigns a random port, optionally bound to ip.
ip can be an IPv4 or an IPv6 literal without brackets. An empty ip binds the system default address, which is dual-stack on most platforms.
func ExternalIP
deprecated
ExternalIP returns the external IP address.
Deprecated: As of due v2.3.0, this function simply calls net.PublicIP.
func ExtractIP ¶
ExtractIP extracts the host from addr.
TCP and UDP addresses are unwrapped directly, which avoids formatting and re-splitting the address string on statements such as LocalIP and RemoteIP. Other address types fall back to splitting addr.String().
func ExtractPort ¶
ExtractPort extracts the port from addr.
TCP and UDP addresses are unwrapped directly, so the port is not parsed from the address string.
func FulfillAddr ¶
FulfillAddr completes addr with the default listen host when it is missing.
An empty host means the system default, which is dual-stack on most platforms, so it is completed to the IPv6 wildcard. An explicit 0.0.0.0 keeps its IPv4-only semantics.
func InternalIP
deprecated
InternalIP returns the internal IP address.
Deprecated: As of due v2.3.0, this function simply calls net.PublicIP.
func ListenNetwork ¶ added in v2.6.7
ListenNetwork returns the network used to listen on addr.
The IPv4 variant of network is selected when the host is an IPv4 literal, so that an explicit IPv4 address, including the IPv4 wildcard, does not create a dual-stack socket. An empty host, the IPv6 wildcard, IPv6 literals and host names keep the given network.
func ParseAddr ¶
ParseAddr parses addr into a listen address and an expose address.
The expose IP is only resolved automatically from the expose argument when addr is a wildcard address, namely 0.0.0.0:[port], [::]:[port] or :[port]. The wildcard listen host is preserved as is: 0.0.0.0 keeps an IPv4-only socket, [::] keeps an IPv6 wildcard socket and an empty host keeps the system default, which is dual-stack on most platforms.
func ParseHostPort ¶ added in v2.6.0
ParseHostPort parses an endpoint into a host and a port.
func SetPrivateIPResolver ¶ added in v2.3.3
func SetPrivateIPResolver(resolver IPResolver)
SetPrivateIPResolver sets the private IP resolver.
func SetPublicIPResolver ¶ added in v2.3.3
func SetPublicIPResolver(resolver IPResolver)
SetPublicIPResolver sets the public IP resolver.