Documentation
¶
Overview ¶
Package netaddr reproduces the inet.af/netaddr IP, IPPrefix and IPRange values that gomplate v3's net.ParseIP, net.ParseIPPrefix and net.ParseIPRange returned. Templates written for v3 call their methods directly and pass them to each other (for example `(net.ParseIPPrefix "10.0.0.0/8").Contains (net.ParseIP "10.1.2.3")`), so the compatibility shims return these types instead of net/netip values. The package name matches inet.af/netaddr so `printf "%T"` output is unchanged.
The values are backed by net/netip and go4.org/netipx; inet.af/netaddr is no longer maintained.
Index ¶
- type IP
- func (ip IP) AppendTo(b []byte) []byte
- func (ip IP) As4() [net.IPv4len]byte
- func (ip IP) As16() [net.IPv6len]byte
- func (ip IP) BitLen() uint8
- func (ip IP) Compare(ip2 IP) int
- func (ip IP) IPAddr() *net.IPAddr
- func (ip IP) Is4() bool
- func (ip IP) Is4in6() bool
- func (ip IP) Is6() bool
- func (ip IP) IsGlobalUnicast() bool
- func (ip IP) IsInterfaceLocalMulticast() bool
- func (ip IP) IsLinkLocalMulticast() bool
- func (ip IP) IsLinkLocalUnicast() bool
- func (ip IP) IsLoopback() bool
- func (ip IP) IsMulticast() bool
- func (ip IP) IsPrivate() bool
- func (ip IP) IsUnspecified() bool
- func (ip IP) IsValid() bool
- func (ip IP) IsZero() bool
- func (ip IP) Less(ip2 IP) bool
- func (ip IP) MarshalBinary() ([]byte, error)
- func (ip IP) MarshalText() ([]byte, error)
- func (ip IP) Netmask(mask []byte) (IPPrefix, error)
- func (ip IP) Next() IP
- func (ip IP) Prefix(bits uint8) (IPPrefix, error)
- func (ip IP) Prior() IP
- func (ip IP) String() string
- func (ip IP) StringExpanded() string
- func (ip IP) Unmap() IP
- func (ip IP) WithZone(zone string) IP
- func (ip IP) Zone() string
- type IPPrefix
- func (p IPPrefix) AppendTo(b []byte) []byte
- func (p IPPrefix) Bits() uint8
- func (p IPPrefix) Contains(ip IP) bool
- func (p IPPrefix) IP() IP
- func (p IPPrefix) IPNet() *net.IPNet
- func (p IPPrefix) IsSingleIP() bool
- func (p IPPrefix) IsValid() bool
- func (p IPPrefix) IsZero() bool
- func (p IPPrefix) MarshalText() ([]byte, error)
- func (p IPPrefix) Masked() IPPrefix
- func (p IPPrefix) Overlaps(o IPPrefix) bool
- func (p IPPrefix) Range() IPRange
- func (p IPPrefix) String() string
- func (p IPPrefix) Valid() bool
- type IPRange
- func (r IPRange) AppendPrefixes(dst []IPPrefix) []IPPrefix
- func (r IPRange) AppendTo(b []byte) []byte
- func (r IPRange) Contains(addr IP) bool
- func (r IPRange) From() IP
- func (r IPRange) IsValid() bool
- func (r IPRange) IsZero() bool
- func (r IPRange) MarshalText() ([]byte, error)
- func (r IPRange) Overlaps(o IPRange) bool
- func (r IPRange) Prefix() (IPPrefix, bool)
- func (r IPRange) Prefixes() []IPPrefix
- func (r IPRange) String() string
- func (r IPRange) To() IP
- func (r IPRange) Valid() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IP ¶
type IP struct {
// contains filtered or unexported fields
}
IP is an IPv4 or IPv6 address, possibly with an IPv6 zone. The zero value is not a valid address.
func (IP) IsGlobalUnicast ¶
IsGlobalUnicast reports whether ip is a global unicast address.
func (IP) IsInterfaceLocalMulticast ¶
IsInterfaceLocalMulticast reports whether ip is an IPv6 interface-local multicast address.
func (IP) IsLinkLocalMulticast ¶
IsLinkLocalMulticast reports whether ip is a link-local multicast address.
func (IP) IsLinkLocalUnicast ¶
IsLinkLocalUnicast reports whether ip is a link-local unicast address.
func (IP) IsLoopback ¶
IsLoopback reports whether ip is a loopback address.
func (IP) IsMulticast ¶
IsMulticast reports whether ip is a multicast address.
func (IP) IsPrivate ¶
IsPrivate reports whether ip is in a private address range (RFC 1918 or RFC 4193).
func (IP) IsUnspecified ¶
IsUnspecified reports whether ip is 0.0.0.0 or ::.
func (IP) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler.
func (IP) MarshalText ¶
MarshalText implements encoding.TextMarshaler; the zero value encodes as "".
func (IP) Next ¶
Next returns the address following ip, or the zero value at the end of the address space.
func (IP) Prior ¶
Prior returns the address before ip, or the zero value at the start of the address space.
func (IP) StringExpanded ¶
StringExpanded is like String but writes IPv6 addresses in full.
type IPPrefix ¶
type IPPrefix struct {
// contains filtered or unexported fields
}
IPPrefix is an IP address and a prefix length (CIDR notation), with the address kept as written.
func FromPrefix ¶
FromPrefix wraps a net/netip prefix, keeping its address as written.
func (IPPrefix) IsSingleIP ¶
IsSingleIP reports whether p contains exactly one address.
func (IPPrefix) MarshalText ¶
MarshalText implements encoding.TextMarshaler; the zero value encodes as "".
func (IPPrefix) Masked ¶
Masked returns p with host bits cleared, or the zero value if p is invalid.
type IPRange ¶
type IPRange struct {
// contains filtered or unexported fields
}
IPRange is an inclusive range of IP addresses.
func (IPRange) AppendPrefixes ¶
AppendPrefixes appends the prefixes that cover r to dst.
func (IPRange) IsValid ¶
IsValid reports whether r has addresses of the same family with From not after To.
func (IPRange) MarshalText ¶
MarshalText implements encoding.TextMarshaler; the zero value encodes as "".