Skip to content

Commit

Permalink
feat(reader): add NetipAddrPort method
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Nov 26, 2023
1 parent 0bd3384 commit 06abcf0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions internal/parse/netip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions reader/netip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 06abcf0

Please sign in to comment.