diff --git a/internal/parse/netip.go b/internal/parse/netip.go index 9e6872e..55e6673 100644 --- a/internal/parse/netip.go +++ b/internal/parse/netip.go @@ -17,6 +17,19 @@ func NetipAddr(sources []Source, key string, return GetParse(sources, key, netip.ParseAddr, options...) } +// NetipAddrPort returns a netip.AddrPort from the first value +// found at the given key from the given sources in order. +// If the value is not a valid netip.AddrPort string, an error is returned +// with the source and key in its message. +// The value is returned as the empty invalid `netip.AddrPort{}` if: +// - the key given is NOT set in any of the sources. +// - By default and unless changed by the AllowEmpty option, if the +// key is set and its corresponding value is empty. +func NetipAddrPort(sources []Source, key string, + options ...Option) (addrPort netip.AddrPort, err error) { + return GetParse(sources, key, netip.ParseAddrPort, options...) +} + // NetipPrefix returns a netip.Prefix from the first value // found at the given key from the given sources in order. // If the value is not a valid netip.Prefix string, an error is returned diff --git a/reader/netip.go b/reader/netip.go index 4f9b761..e20ffde 100644 --- a/reader/netip.go +++ b/reader/netip.go @@ -19,6 +19,19 @@ func (r *Reader) NetipAddr(key string, options ...Option) ( return parse.NetipAddr(r.sources, key, parseOptions...) } +// NetipAddrPort returns a netip.AddrPort from the value found at the given key. +// If the value is not a valid netip.AddrPort string, an error is returned +// with the source and key in its message. +// The value is returned as the empty invalid `netip.AddrPort{}` if: +// - the given key is NOT set. +// - By default and unless changed by the AllowEmpty option, if the +// given key is set and its corresponding value is empty. +func (r *Reader) NetipAddrPort(key string, options ...Option) ( + addr netip.AddrPort, err error) { + parseOptions := r.makeParseOptions(options) + return parse.NetipAddrPort(r.sources, key, parseOptions...) +} + // NetipPrefix returns a netip.Prefix from the value found at the given key. // If the value is not a valid netip.Prefix string, an error is returned // with the source and key in its message.