Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetOrDefault ¶
func GetOrDefault[T Parseable](envVar string, defaultVal T, opts ...ParseOption) (dest T, err error)
GetOrDefault attempts to parse the environment variable provided. If it is empty or missing, the default value is used.
If an error is encountered, depending on whether the `WithDefaultOnError` option is provided it will either fall back or return the error back to the client.
Types ¶
type Loader ¶
Loader is an alias for a function that loads values from the env. It mirrors the signature of os.Getenv.
type ParseOption ¶
type ParseOption func(o *parseOpts) error
ParseOption is a means to customize parse options via variadic parameters.
func WithDefaultOnError ¶
func WithDefaultOnError(fallback bool) ParseOption
WithDefaultOnError informs the parser that if an error is encountered during parsing, it should fallback to the default value.
func WithLoader ¶
func WithLoader(loader Loader) ParseOption
WithLoader allows overriding how env vars are loaded.
Primarily used for testing.