Documentation ¶
Overview ¶
Package parse provides generic functions to parse values from strings found from given sources interfaces. It essentially exists due to its use of generics, where its sibling package reader is not using generics.
Index ¶
- Variables
- func BoolPtr(sources []Source, key string, options ...Option) (boolPtr *bool, err error)
- func CSV(sources []Source, key string, options ...Option) (values []string)
- func CSVInt(sources []Source, key string, options ...Option) (values []int, err error)
- func CSVInt16(sources []Source, key string, options ...Option) (values []int16, err error)
- func CSVInt32(sources []Source, key string, options ...Option) (values []int32, err error)
- func CSVInt64(sources []Source, key string, options ...Option) (values []int64, err error)
- func CSVInt8(sources []Source, key string, options ...Option) (values []int8, err error)
- func CSVNetipAddrPorts(sources []Source, key string, options ...Option) (addrPorts []netip.AddrPort, err error)
- func CSVNetipAddresses(sources []Source, key string, options ...Option) (addresses []netip.Addr, err error)
- func CSVNetipPrefixes(sources []Source, key string, options ...Option) (prefixes []netip.Prefix, err error)
- func CSVParse[T any](sources []Source, key string, parse ParseFunc[T], options ...Option) (values []T, err error)
- func CSVUint(sources []Source, key string, options ...Option) (values []uint, err error)
- func CSVUint16(sources []Source, key string, options ...Option) (values []uint16, err error)
- func CSVUint32(sources []Source, key string, options ...Option) (values []uint32, err error)
- func CSVUint64(sources []Source, key string, options ...Option) (values []uint64, err error)
- func CSVUint8(sources []Source, key string, options ...Option) (values []uint8, err error)
- func Duration(sources []Source, key string, options ...Option) (duration time.Duration, err error)
- func DurationPtr(sources []Source, key string, options ...Option) (durationPtr *time.Duration, err error)
- func Float32(sources []Source, key string, options ...Option) (f float32, err error)
- func Float32Ptr(sources []Source, key string, options ...Option) (pointer *float32, err error)
- func Float64(sources []Source, key string, options ...Option) (f float64, err error)
- func Float64Ptr(sources []Source, key string, options ...Option) (pointer *float64, err error)
- func Get(sources []Source, key string, options ...Option) (value *string)
- func GetParse[T any](sources []Source, key string, parse ParseFunc[T], options ...Option) (value T, err error)
- func GetParsePtr[T any](sources []Source, key string, parse ParseFunc[T], options ...Option) (value *T, err error)
- func Int(sources []Source, key string, options ...Option) (n int, err error)
- func Int16(sources []Source, key string, options ...Option) (n int16, err error)
- func Int16Ptr(sources []Source, key string, options ...Option) (pointer *int16, err error)
- func Int32(sources []Source, key string, options ...Option) (n int32, err error)
- func Int32Ptr(sources []Source, key string, options ...Option) (pointer *int32, err error)
- func Int64(sources []Source, key string, options ...Option) (n int64, err error)
- func Int64Ptr(sources []Source, key string, options ...Option) (pointer *int64, err error)
- func Int8(sources []Source, key string, options ...Option) (n int8, err error)
- func Int8Ptr(sources []Source, key string, options ...Option) (pointer *int8, err error)
- func IntPtr(sources []Source, key string, options ...Option) (intPtr *int, err error)
- func NetipAddr(sources []Source, key string, options ...Option) (addr netip.Addr, err error)
- func NetipAddrPort(sources []Source, key string, options ...Option) (addrPort netip.AddrPort, err error)
- func NetipPrefix(sources []Source, key string, options ...Option) (addr netip.Prefix, err error)
- func String(sources []Source, key string, options ...Option) (value string)
- func Uint(sources []Source, key string, options ...Option) (n uint, err error)
- func Uint16(sources []Source, key string, options ...Option) (n uint16, err error)
- func Uint16Ptr(sources []Source, key string, options ...Option) (uint16Ptr *uint16, err error)
- func Uint32(sources []Source, key string, options ...Option) (n uint32, err error)
- func Uint32Ptr(sources []Source, key string, options ...Option) (uint32Ptr *uint32, err error)
- func Uint64(sources []Source, key string, options ...Option) (n uint64, err error)
- func Uint64Ptr(sources []Source, key string, options ...Option) (pointer *uint64, err error)
- func Uint8(sources []Source, key string, options ...Option) (n uint8, err error)
- func Uint8Ptr(sources []Source, key string, options ...Option) (uint8Ptr *uint8, err error)
- func UintPtr(sources []Source, key string, options ...Option) (pointer *uint, err error)
- type Option
- type ParseFunc
- type Source
Constants ¶
This section is empty.
Variables ¶
var (
ErrValueNotInRange = errors.New("value is not in range")
)
Functions ¶
func BoolPtr ¶
BoolPtr returns a pointer to a `bool` from the first value found at the given key in the given sources in order.
- 'true' string values are: "enabled", "yes", "on", "true".
- 'false' string values are: "disabled", "no", "off", "false".
The value is returned as `nil` 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.
Otherwise, if the value is not one of the above, an error is returned with the key name and source name in its message.
func CSV ¶
CSV returns a slice of strings from the first comma separated value found from the given sources in order. The entire CSV string value may be modified depending on the parse default settings and the parse options given. The parse default settings are to:
- Trim line endings suffixes \r\n and \n.
- Trim spaces.
- Trim quotes.
- Force lowercase.
The slice is returned as `nil` if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set and its corresponding value is empty.
func CSVInt ¶
CSVInt returns a slice of int from the first comma separated string value found at the given key in the given sources in order. It returns an error if any value is not a valid int string. The slice is returned as `nil` if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set and the corresponding value is empty.
func CSVInt16 ¶
CSVInt16 returns a slice of int16 from the first comma separated string value found at the given key in the given sources in order. It returns an error if any value is not a valid int16 string. The slice is returned as `nil` if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set and the corresponding value is empty.
func CSVInt32 ¶
CSVInt32 returns a slice of int32 from the first comma separated string value found at the given key in the given sources in order. It returns an error if any value is not a valid int32 string. The slice is returned as `nil` if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set and the corresponding value is empty.
func CSVInt64 ¶
CSVInt64 returns a slice of int64 from the first comma separated string value found at the given key in the given sources in order. It returns an error if any value is not a valid int64 string. The slice is returned as `nil` if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set and the corresponding value is empty.
func CSVInt8 ¶
CSVInt8 returns a slice of int8 from the first comma separated string value found at the given key in the given sources in order. It returns an error if any value is not a valid int8 string. The slice is returned as `nil` if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set and the corresponding value is empty.
func CSVNetipAddrPorts ¶
func CSVNetipAddrPorts(sources []Source, key string, options ...Option) (addrPorts []netip.AddrPort, err error)
CSVNetipAddrPorts returns a slice of netip.AddrPort from the first comma separated string value found at the given key from the given sources in order, and returns an error if any value is not a valid netip.AddrPort string.
The slice is returned as `nil` if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set and its corresponding value is empty.
The entire CSV string value may be modified depending on the parse default settings and the parse options given. The parse default settings are to:
- Trim line endings suffixes \r\n and \n.
- Trim spaces.
- Trim quotes.
- Force lowercase.
func CSVNetipAddresses ¶
func CSVNetipAddresses(sources []Source, key string, options ...Option) (addresses []netip.Addr, err error)
CSVNetipAddresses returns a slice of netip.Addr from the first comma separated string value found at the given key from the given sources in order, and returns an error if any value is not a valid netip.Addr string.
The slice is returned as `nil` if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set and its corresponding value is empty.
The entire CSV string value may be modified depending on the parse default settings and the parse options given. The parse default settings are to:
- Trim line endings suffixes \r\n and \n.
- Trim spaces.
- Trim quotes.
- Force lowercase.
func CSVNetipPrefixes ¶
func CSVNetipPrefixes(sources []Source, key string, options ...Option) (prefixes []netip.Prefix, err error)
CSVNetipPrefixes returns a slice of netip.Prefix from the first comma separated string value found at the given key from the given sources in order, and returns an error if any value is not a valid netip.Prefix string.
The slice is returned as `nil` if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set and its corresponding value is empty.
The entire CSV string value may be modified depending on the parse default settings and the parse options given. The parse default settings are to:
- Trim line endings suffixes \r\n and \n.
- Trim spaces.
- Trim quotes.
- Force lowercase.
func CSVParse ¶
func CSVParse[T any](sources []Source, key string, parse ParseFunc[T], options ...Option) (values []T, err error)
CSVParse returns a slice of type T from the first comma separated string value found at the given key in the given sources in order. Each comma separated values is parsed using the provided `parse` function. The slice is returned as `nil` if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set and the corresponding value is empty.
func CSVUint ¶
CSVUint returns a slice of uint from the first comma separated string value found at the given key in the given sources in order. It returns an error if any value is not a valid uint string. The slice is returned as `nil` if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set and the corresponding value is empty.
func CSVUint16 ¶
CSVUint16 returns a slice of uint8 from the first comma separated string value found at the given key in the given sources in order. It returns an error if any value is not a valid uint8 string. The slice is returned as `nil` if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set and the corresponding value is empty.
func CSVUint32 ¶
CSVUint32 returns a slice of uint32 from the first comma separated string value found at the given key in the given sources in order. It returns an error if any value is not a valid uint32 string. The slice is returned as `nil` if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set and the corresponding value is empty.
func CSVUint64 ¶
CSVUint64 returns a slice of uint64 from the first comma separated string value found at the given key in the given sources in order. It returns an error if any value is not a valid uint64 string. The slice is returned as `nil` if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set and the corresponding value is empty.
func CSVUint8 ¶
CSVUint8 returns a slice of uint8 from the first comma separated string value found at the given key in the given sources in order. It returns an error if any value is not a valid uint8 string. The slice is returned as `nil` if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set and the corresponding value is empty.
func Duration ¶
Duration returns a `time.Duration` parsed from the first value found at the given key from the given sources in order. If the value is not a valid time.Duration string, an error is returned with the source name and key in its message. The value is returned as `0` 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 DurationPtr ¶
func DurationPtr(sources []Source, key string, options ...Option) (durationPtr *time.Duration, err error)
DurationPtr returns a pointer to a `time.Duration` from the first value found at the given key from the given sources in order. If the value is not a valid time.Duration string, an error is returned with the source name and key in its message. The value is returned as `nil` 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 Float32 ¶
Float32 returns a `float32` from the first value found at the given key in the given sources in order. If the value is not a valid float32 string, an error is returned with the key name and the source name in its message. The value is returned as `0` 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 Float32Ptr ¶
Float32 returns a pointer to a `float32` from the first value found at the given key in the given sources in order. If the value is not a valid float32 string, an error is returned with the key name and the source name in its message. The value is returned as `nil` 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 Float64 ¶
Float64 returns a `float64` from the first value found at the given key in the given sources in order. If the value is not a valid float64 string, an error is returned with the key name and the source name in its message. The value is returned as `0` 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 Float64Ptr ¶
Float64 returns a `float64` from the first value found at the given key in the given sources in order. If the value is not a valid float64 string, an error is returned with the key name and the source name in its message. The value is returned as `nil` 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 Get ¶
Get returns the first value found at the given key from the given sources in order, as a string pointer.
The value is returned as `nil` if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set in one of the sources and its corresponding value is empty.
Otherwise, the value may be modified depending on the parse default settings and the parse options given.
The parse default settings are to:
- Trim line endings suffixes \r\n and \n.
- Trim spaces.
- Trim quotes.
- Force lowercase.
func GetParse ¶
func GetParse[T any](sources []Source, key string, parse ParseFunc[T], options ...Option) (value T, err error)
GetParse parses the first value found at the given key from the given sources in order, using the given parse function, and returns the typed parsed value with an eventual error containing the key name and the source name in its message.
The value is returned as the empty `T` value if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set in a source and its corresponding value is empty.
Note the value from the map may be modified depending on the parse default settings and the parse options given.
The parse default settings are to:
- Trim line endings suffixes \r\n and \n.
- Trim spaces.
- Trim quotes.
- Force lowercase.
func GetParsePtr ¶
func GetParsePtr[T any](sources []Source, key string, parse ParseFunc[T], options ...Option) (value *T, err error)
GetParsePtr parses the first value found at the given key from the given sources in order, using the given parse function, and returns the typed pointer to the parsed value with an eventual error which contains the key name and source name in its message.
The value is returned as `nil` if:
- the key given is NOT set in any of the sources.
- By default and unless changed by the AcceptEmpty option, if the key is set in the mapping and its corresponding value is empty.
Note the value from the map may be modified depending on the parse default settings and the parse options given.
The parse default settings are to:
- Trim line endings suffixes \r\n and \n.
- Trim spaces.
- Trim quotes.
- Force lowercase.
func Int ¶
Int returns an `int` from the first value found at the given key in the given sources in order. If the value is not a valid integer string, an error is returned with the key name and the source name in its message. The value is returned as `0` 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 Int16 ¶
Int16 returns an `int16` from the first value found at the given key in the given sources in order. If the value is not an integer string between -32768 and 32767, an error is returned with the key name and the source name in its message. The value is returned as `0` 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 Int16Ptr ¶
Int16Ptr returns a pointer to an `int8` from the first value found at the given key in the given sources in order. If the value is not an integer string between -32768 to 32767, an error is returned with the key name and source name in its message. The value is returned as `nil` 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 Int32 ¶
Int32 returns an `int32` from the first value found at the given key in the given sources in order. If the value is not an integer string between -2147483648 and 2147483647, an error is returned with the key name and the source name in its message. The value is returned as `0` 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 Int32Ptr ¶
Int32Ptr returns a pointer to an `int32` from the first value found at the given key in the given sources in order. If the value is not an integer string between -2147483648 to 2147483647, an error is returned with the key name and source name in its message. The value is returned as `nil` 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 Int64 ¶
Int64 returns an `int64` from the first value found at the given key in the given sources in order. If the value is not an integer string between –2^63 and 2^63 - 1, an error is returned with the key name and the source name in its message. The value is returned as `0` 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 Int64Ptr ¶
Int64Ptr returns a pointer to an `int64` from the first value found at the given key in the given sources in order. If the value is not an integer string between -2^63 to 2^63 - 1, an error is returned with the key name and source name in its message. The value is returned as `nil` 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 Int8 ¶
Int8 returns an `int8` from the first value found at the given key in the given sources in order. If the value is not an integer string between -128 and 127, an error is returned with the key name and the source name in its message. The value is returned as `0` 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 Int8Ptr ¶
Int8Ptr returns a pointer to an `int8` from the first value found at the given key in the given sources in order. If the value is not an integer string between -128 to 127, an error is returned with the key name and source name in its message. The value is returned as `nil` 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 IntPtr ¶
IntPtr returns a pointer to an `int` from the first value found at the given key in the given sources in order. If the value is not a valid integer string, an error is returned with the key name and source name in its message. The value is returned as `nil` 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 NetipAddr ¶
NetipAddr returns a netip.Addr from the first value found at the given key from the given sources in order. If the value is not a valid netip.Addr string, an error is returned with the source and key in its message. The value is returned as the empty invalid `netip.Addr{}` 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 ¶
func NetipAddrPort(sources []Source, key string, options ...Option) (addrPort netip.AddrPort, err error)
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 NetipPrefix ¶
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 with the key name and kind (source) in its message. The value is returned as the empty invalid `netip.Prefix{}` 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 String ¶
String returns the first string value found at the given key from the given sources in order. The value may be modified depending on the parse default settings and the parse options given. The parse default settings are to:
- Trim line endings suffixes \r\n and \n.
- Trim spaces.
- Trim quotes.
- Force lowercase.
If the key is not set in any of the sources, the empty string is returned.
func Uint ¶
Uint returns an `uint` from the first value found at the given key in the given sources in order. If the value is not a valid unsigned integer string matching the current system architecture, an error is returned with the key name and the source name in its message. The value is returned as `0` 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 Uint16 ¶
Uint16 returns an `uint16` from the first value found at the given key in the given sources in order. If the value is not a valid integer string between 0 and 65535, an error is returned with the key name and the source name in its message. The value is returned as `0` 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 Uint16Ptr ¶
Uint16Ptr returns a pointer to an `uint16` from the first value found at the given key in the given sources in order. If the value is not a valid integer string between 0 and 65535, an error is returned with the key name and source name in its message. The value is returned as `nil` 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 Uint32 ¶
Uint32 returns an `uint32` from the first value found at the given key in the given sources in order. If the value is not a valid integer string between 0 and 4294967295, an error is returned with the key name and the source name in its message. The value is returned as `0` 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 Uint32Ptr ¶
Uint32Ptr returns a pointer to an `uint32` from the first value found at the given key in the given sources in order. If the value is not a valid integer string between 0 and 4294967295, an error is returned with the key name and source name in its message. The value is returned as `nil` 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 Uint64 ¶
Uint64 returns an `uint64` from the first value found at the given key in the given sources in order. If the value is not a valid integer string between 0 and 18446744073709551615, an error is returned with the key name and the source name in its message. The value is returned as `0` 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 Uint64Ptr ¶
Uint64Ptr returns a pointer to an `uint64` from the first value found at the given key in the given sources in order. If the value is not a valid integer string bigger than 0, an error is returned with the key name and source name in its message. The value is returned as `nil` 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 Uint8 ¶
Uint8 returns an `uint8` from the first value found at the given key in the given sources in order. If the value is not a valid integer string between 0 and 255, an error is returned with the key name and the source name in its message. The value is returned as `0` 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 Uint8Ptr ¶
Uint8Ptr returns a pointer to an `uint8` from the first value found at the given key in the given sources in order. If the value is not a valid integer string between 0 and 255, an error is returned with the key name and source name in its message. The value is returned as `nil` 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 UintPtr ¶
UintPtr returns a pointer to an `uint` from the first value found at the given key in the given sources in order. If the value is not a valid unsigned integer string matching the current system architecture, an error is returned with the key name and source name in its message. The value is returned as `nil` 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.
Types ¶
type Option ¶
type Option func(s *settings)
Option is an option to modify the behavior of the underlying `get` function which is called by all the other functions.
func AcceptEmpty ¶
AcceptEmpty, if set to true, makes the code distinguish between unset keys and empty values from a given source. By default, the code does not distinguish between the two cases.
func ForceLowercase ¶
ForceLowercase forces the string values read from any source given to be lowercased or not, depending on the `lowercase` argument given.
func IsRetro ¶
func IsRetro(handleDeprecatedKey func(source, deprecateKey, currentKey string), currentKey string) Option
IsRetro indicates that all the keys given are retro-compatible keys, and that the currentKey given should be used instead.
func RetroKeys ¶
func RetroKeys(handleDeprecatedKey func(source, deprecateKey, currentKey string), deprecatedKeys ...string) Option
RetroKeys specifies a list of keys that are deprecated and replaced by the current key. The oldest deprecated key should be placed first in the list of deprecated keys, so it gets checked first, which is especially important if for example default variable values are set in the program or operating system matching more recent keys. The `handleDeprecatedKey` function is called when a deprecated key is used, with the source name, the deprecated key and the current key as arguments.
type ParseFunc ¶
ParseFunc is a function that parses a string into a value of type T and returns an error if the parsing failed.
type Source ¶
type Source interface { // String can return for example 'environment variable' or 'flag' String() string // Get returns the value of the key and whether it is set. Get(key string) (value string, isSet bool) // KeyTransform transforms a standardized key to a key specific to // the source. For example SERVER_ADDRESS becomes server-address for // the flags source. KeyTransform(key string) string }
Source is a named key-value source.