Documentation
¶
Overview ¶
Package net provides additional networking utilities and helpers.
Index ¶
Constants ¶
const DefaultPort = 3264
DefaultPort is used to allocate a port for services on the network when not specified directly. The port number refers to our office in A.V. Williams during graduate school and we've commonly used it in many applications. The DefaultPort is primarily used in ResolveAddr.
Variables ¶
This section is empty.
Functions ¶
func ExternalIP ¶
ExternalIP looks up an the first available external IP address used by local network interfaces. This function returns a string representation of the IP address that can be parsed by net.IPAddr or other tools.
NOTE: this function does not refer to the external network IP address, but rather non-local or loopback addresses on the machine. If the machine receives an internal DHCP provied IP address, then this function will detect that, not the IP address of the router. To find the publically accessible IP address of the machine use PublicIP.
func FreePort ¶
FreePort asks the kernel for a free, open port that is ready to use. https://github.com/phayes/freeport
func PublicIP ¶
PublicIP makes an external HTTP request to myexternalip.com in order to discover the publically available IP address of the machine. This is especially useful when the machine sits behind a NAT device such as a router that performs port forwarding.
NOTE: the myexternalip.com service maintains a rate limit of 30 requests per minute, do not exceed it!
func ResolveAddr ¶
ResolveAddr accepts an address as a string and if the IP address is missing it replaces it with the result from ExternalIP then returns the addr string. Likewise if the Port is missing, it returns an address with the DefaultPort appended to the address string.
Types ¶
This section is empty.