Documentation
¶
Overview ¶
Package addr provides functions to retrieve local IP addresses from device interfaces.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrIPNotFound no IP address found, and explicit IP not provided. ErrIPNotFound = errors.New("no IP address found, and explicit IP not provided") // ErrNoAddress is returned when no address is provided. ErrNoAddress = errors.New("no adddress provided") // ErrPortInvalid is returned when the provided port is below 0. ErrPortInvalid = errors.New("invalid port provided, must be between 0 and 65535") // ErrInvalidIP is returned an invalid IP is provided. ErrInvalidIP = errors.New("invalid IP provided") )
Functions ¶
func Extract ¶
Extract returns a valid IP address. If the address provided is a valid address, it will be returned directly. Otherwise the available interfaces be itterated over to find an IP address, prefferably private.
func GetAddress ¶
GetAddress will validate the address if one is provided, otherwise it will return an interface and port to listen on.
If you want to listen on all interfaces, you have to explicityly set '0.0.0.0:<port>'.
If no IP address is provides, as ':8080' the first private interface will be selected to listen on. If none are available, a public IP is selected.
func ValidateAddress ¶
ValidateAddress will do basic validation on an address string.
Address example:
- :8080
- 192.168.1.1:8080
- [2001:db8::1]:8080
Types ¶
This section is empty.