Documentation ¶
Overview ¶
Package util provides common utility functions used by multiple portions of wirelink, primarily providing wrappers and helpers for core go libraries and constructs.
Index ¶
- func CloneBytes(data []byte) []byte
- func CloneIPNet(ipn net.IPNet) net.IPNet
- func CloneUDPAddr(addr *net.UDPAddr) *net.UDPAddr
- func DecodeFrom(value encoding.BinaryUnmarshaler, readLen int, reader io.Reader) error
- func IPToBytes(ip net.IP) (ret [net.IPv6len]byte)
- func IsGloballyRoutable(ip net.IP) bool
- func IsIPv6LLMatch(expected net.IP, actual *net.IPNet, local bool) bool
- func MustByte(value byte, err error) byte
- func MustBytes(value []byte, err error) []byte
- func MustInt64(value int64, err error) int64
- func NormalizeIP(ip net.IP) net.IP
- func SortIPNetSlice(slice []net.IPNet) []net.IPNet
- func Ternary(value bool, trueResult, falseResult interface{}) interface{}
- func TimeMax() time.Time
- func UDPEqualIPPort(a, b *net.UDPAddr) bool
- func WrapOrNewf(err error, format string, args ...interface{}) error
- type ByteReader
- type Decodable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloneBytes ¶ added in v0.6.1
CloneBytes returns a new copy of the input data
func CloneIPNet ¶ added in v0.10.0
CloneIPNet makes a deep copy of the given value
func CloneUDPAddr ¶ added in v0.10.0
CloneUDPAddr makes a deep copy of the given address
func DecodeFrom ¶ added in v0.6.0
DecodeFrom provides an equivalent function to Decodable.DecodeFrom, but for types that implement BinaryUnmarshaler and which have a fixed known length, e.g. to provide a default implementation for Decodable for such types
func IPToBytes ¶ added in v0.1.0
IPToBytes returns the given IP normalized to a 16 byte array, suitable for use as a map key among other things
func IsGloballyRoutable ¶ added in v0.12.2
IsGloballyRoutable checks if an IP address looks routable across the internet or not. It will return false for any IP that is not a Global Unicast address, and also for certain special reserved subnets that are used within site-level domains but are not meant to be routed on the internet.
func IsIPv6LLMatch ¶
IsIPv6LLMatch checks if a given expected IPv6 address matches an actual address + mask, checking if the mask is of the expected form. The mask is expected to be /128 if local is false, or /64 if it is true
func MustByte ¶ added in v0.6.0
MustByte is a helper, esp. for ByteReader, that takes a tuple of a byte and maybe an error and panics if there is an error, or else returns the byte
func MustBytes ¶ added in v0.6.0
MustBytes is a helper, esp. for BinaryMarshaller, that takes a tuple of a byte slice and maybe an error and panics if there is an error, or else returns the byte slice
func MustInt64 ¶ added in v0.6.0
MustInt64 is a helper, esp. for encoding.binary, that takes a tuple of an int64 and maybe an error and panics if there is an error, or else returns the int64
func NormalizeIP ¶
NormalizeIP returns a version of the given ip normalized to its underlying family, instead of the "always in IPv6 container" format that is often used, so IPv4 values will have a length of 4 and IPv6 ones a length of 16
func SortIPNetSlice ¶ added in v0.9.0
SortIPNetSlice sorts a slice of IPNets by their string value, returning the (modified in place) slice. OMG want generics.
func Ternary ¶ added in v0.11.1
func Ternary(value bool, trueResult, falseResult interface{}) interface{}
Ternary turns a trivial if/else into a function call
func TimeMax ¶ added in v0.1.2
TimeMax is the maximum representable time in go. see: https://stackoverflow.com/a/32620397/7649 see also `time.go` in the runtime
func UDPEqualIPPort ¶ added in v0.9.0
UDPEqualIPPort checks if to UDPAddrs are equal in terms of their IP and Port fields, but ignoring any Zone value
func WrapOrNewf ¶ added in v0.6.0
WrapOrNewf calls fmt.Errorf with varying format depending on whether err is nil, always returning an error value
Types ¶
type ByteReader ¶ added in v0.12.0
type ByteReader interface { io.Reader io.ByteReader }
ByteReader combines io.Reader and io.ByteReader