Documentation
¶
Overview ¶
Package net implements the functions, types, and interfaces for the module.
Index ¶
- Constants
- Variables
- func ExtractIP(scheme, host, hostPort string) (string, error)
- func GenerateDynamic(option *EndpointOptions, scheme, addr string) (string, error)
- func HostAddr(provider NetworkInterfaceProvider, opts ...Option) string
- func IsPublicRoutableIP(addr string) bool
- func IsUsableHostIP(addr string) bool
- func ParseIP(ip IP) int64
- func PreferIPv4Strategy(ips []net.IP) (net.IP, error)
- func PreferPublicIPStrategy(ips []net.IP) (net.IP, error)
- func RealHostAddr(opts ...Option) string
- type EndpointOptions
- type HostConfig
- type IP
- type IPSelectionStrategy
- type InterfaceWithAddrs
- type NetworkInterfaceProvider
- type Option
Constants ¶
const ( IPv4len = net.IPv4len IPv6len = net.IPv6len )
Variables ¶
var ErrNoIPFound = errors.New("no ip found")
Functions ¶
func ExtractIP ¶ added in v0.3.24
ExtractIP will extract the IP address from the host, and if the host is empty, it will extract the local IP address.
func GenerateDynamic ¶ added in v0.3.24
func GenerateDynamic(option *EndpointOptions, scheme, addr string) (string, error)
GenerateDynamic will generate a dynamic endpoint.
func HostAddr ¶
func HostAddr(provider NetworkInterfaceProvider, opts ...Option) string
HostAddr now accepts a NetworkInterfaceProvider.
func IsPublicRoutableIP ¶ added in v0.3.24
IsPublicRoutableIP checks if the given IP address is a global unicast address and not a private or multicast address.
func IsUsableHostIP ¶ added in v0.3.24
IsUsableHostIP checks if the given IP address is a usable host IP (not loopback, link-local, or unspecified).
func PreferIPv4Strategy ¶ added in v0.3.24
PreferIPv4Strategy prefers IPv4 addresses over IPv6
func PreferPublicIPStrategy ¶ added in v0.3.24
PreferPublicIPStrategy prefers public IPs over private ones
func RealHostAddr ¶ added in v0.3.22
RealHostAddr is a convenience function for external callers to use the real network provider.
Types ¶
type EndpointOptions ¶ added in v0.3.24
type EndpointOptions struct {
// EnvVar specifies the environment variable name that may contain the host IP
EnvVar string
// HostIP directly specifies the host IP to use (overrides EnvVar if both are set)
HostIP string
// EndpointFunc allows custom endpoint generation logic
EndpointFunc func(scheme, host, port string) (string, error)
// IPStrategy defines how to select an IP when multiple are available
IPStrategy IPSelectionStrategy
// PreferPublicIP indicates whether to prefer public IPs over private ones
PreferPublicIP bool
// AllowedInterfaces specifies which network interfaces to consider
AllowedInterfaces []string
// CloudMetadataEnabled enables/disables cloud provider metadata lookup
CloudMetadataEnabled bool
}
EndpointOptions contains configuration for endpoint generation
func DefaultOptions ¶ added in v0.3.24
func DefaultOptions() *EndpointOptions
DefaultOptions returns the default endpoint options
func (*EndpointOptions) WithCloudMetadata ¶ added in v0.3.24
func (o *EndpointOptions) WithCloudMetadata(enabled bool) *EndpointOptions
WithCloudMetadata enables/disables cloud metadata lookup
func (*EndpointOptions) WithEnvVar ¶ added in v0.3.24
func (o *EndpointOptions) WithEnvVar(name string) *EndpointOptions
WithEnvVar sets the environment variable name for host IP
func (*EndpointOptions) WithHostIP ¶ added in v0.3.24
func (o *EndpointOptions) WithHostIP(ip string) *EndpointOptions
WithHostIP directly sets the host IP
func (*EndpointOptions) WithIPStrategy ¶ added in v0.3.24
func (o *EndpointOptions) WithIPStrategy(strategy IPSelectionStrategy) *EndpointOptions
WithIPStrategy sets the IP selection strategy
type HostConfig ¶ added in v0.0.20
type HostConfig struct {
// contains filtered or unexported fields
}
HostConfig defines the configuration for the host.
func DefaultConfig ¶ added in v0.3.21
func DefaultConfig() HostConfig
DefaultConfig returns the default host configuration.
type IPSelectionStrategy ¶ added in v0.3.24
IPSelectionStrategy defines how to select an IP from multiple available IPs
type InterfaceWithAddrs ¶ added in v0.3.21
InterfaceWithAddrs abstracts a network interface and its addresses for mocking.
type NetworkInterfaceProvider ¶ added in v0.3.22
type NetworkInterfaceProvider interface {
Interfaces() ([]InterfaceWithAddrs, error)
}
NetworkInterfaceProvider now returns InterfaceWithAddrs.
type Option ¶ added in v0.0.20
type Option func(*HostConfig)
Option is a function that configures a HostConfig.
func WithCIDRFilters ¶ added in v0.0.20
WithCIDRFilters sets CIDR ranges to filter interfaces by.
func WithEnvVar ¶ added in v0.0.20
WithEnvVar sets the environment variable name to look for an IP address.
func WithFallback ¶ added in v0.0.20
WithFallback enables or disables falling back to the first available IP if no other method succeeds.
func WithInterfacePatterns ¶ added in v0.0.20
WithInterfacePatterns sets patterns to match interface names against.