Documentation ¶
Index ¶
- Variables
- func Bool(name string, def bool) bool
- func Int(name string, def int) int
- func NotEmpty(name string) bool
- func OneOfOr[T any](names []string, def T, parse func(envVal string) (T, error)) T
- func OneOfRequired[T any](names []string, parse func(envVal string) (T, error)) (T, error)
- func OneOfRequiredString(names []string) (string, error)
- func OneOfString(names []string, def string) string
- func Or[T any](name string, def T, parse func(envVal string) (T, error)) T
- func PathSlice(name string, def []string) []string
- func Required[T any](name string, parse func(envVal string) (T, error)) (T, error)
- func RequiredBool(name string) (bool, error)
- func RequiredInt(name string) (int, error)
- func RequiredSlice[T any](name string, sep string, parse func(envVal string) (T, error)) ([]T, error)
- func RequiredString(name string) (string, error)
- func RequiredStringSlice(name string, sep string) ([]string, error)
- func Slice[T any](name string, def []T, sep string, parse func(envVal string) (T, error)) []T
- func StrictBool(name string, def bool) (bool, error)
- func StrictInt(name string, def int) (int, error)
- func StrictOneOfOr[T any](names []string, def T, parse func(envVal string) (T, error)) (T, error)
- func StrictOr[T any](name string, def T, parse func(envVal string) (T, error)) (T, error)
- func StrictSlice[T any](name string, def []T, sep string, parse func(envVal string) (T, error)) ([]T, error)
- func String(name, def string) string
- func StringSlice(name string, def []string, sep string) []string
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEnvVarNotFound is returned when an environment variable is not found (os.LookupEnv error). ErrEnvVarNotFound = errors.New("environment variable not found") // ErrParseEnvVar is returned when an environment variable is found but cannot be parsed. ErrParseEnvVar = errors.New("error parsing environment variable") )
Common errors for environment variable loading.
Functions ¶
func OneOfOr ¶
OneOfOr grabs the first env variable found or the default value. If there is a parsing error, it is logged with slog.Debug.
func OneOfRequired ¶
OneOfRequired grabs the first env variable found. If none of the variables are found, an error is returned. If any of the parsed variables have a parsing error, it is returned.
func OneOfRequiredString ¶
OneOfRequiredString is a helper for OneOfRequired[string].
func OneOfString ¶
OneOfString is a helper for OneOfOr[string].
func Or ¶
Or grabs the env variable or the default value. If there is a parsing error, it is logged with slog.Debug.
func PathSlice ¶
PathSlice grabs the env variable as an array splitting on the default (OS specific) path list separator.
func Required ¶
Required grabs a required env variable. If the variable is not found, an error is returned. If there is a parsing error, it is returned.
func RequiredBool ¶
RequiredBool is a helper for Required[bool].
func RequiredInt ¶
RequiredInt is a helper for Required[int].
func RequiredSlice ¶
func RequiredSlice[T any](name string, sep string, parse func(envVal string) (T, error)) ([]T, error)
StrictSlice grabs the env variable as a slice or the default value. If there is a parsing error, it is logged with slog.Debug.
func RequiredString ¶
RequiredString is a helper for Required[string].
func RequiredStringSlice ¶
RequiredStringSlice is a helper for RequiredSlice[string].
func Slice ¶
Slice grabs the env variable as a slice or the default value. If there is a parsing error, it is logged with slog.Debug.
func StrictBool ¶
StrictBool is a helper for StrictOr[bool].
func StrictOneOfOr ¶
StrictOr grabs the first env variable found or the default value. If there is a parsing error, it is returned.
func StrictOr ¶
StrictOr grabs the env variable or the default value. If there is a parsing error, it is returned.
Types ¶
This section is empty.