Documentation
¶
Overview ¶
Package env provides a straightforward way to retrieve environment variables and offers a default value if the specified key is not present.
Index ¶
- Constants
- func Bool(key string, fallback bool) bool
- func Duration(key string, fallback time.Duration) time.Duration
- func Float64(key string, fallback float64) float64
- func Int(key string, fallback int) int
- func Int64(key string, fallback int64) int64
- func List[T any](key string, parser Parser[T], fallback []T) []T
- func Parse[T any](key string, parser Parser[T], fallback T) T
- func String(key, fallback string) string
- type Parser
Constants ¶
const Parsers = parsers(1)
Parsers is a namespace that can be used to access all available parsers.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Bool returns the bool value if the key exists; otherwise, it returns the fallback value.
func Duration ¶
Duration returns the time.Duration value if the key exists; otherwise, it returns the fallback value.
func Float64 ¶
Float64 returns the float64 value if the key exists; otherwise, it returns the fallback value.
func Int64 ¶
Int64 returns the int64 value if the key exists; otherwise, it returns the fallback value.
func List ¶
List retrieves the environment variable with the specified key and attempts to parse it into a slice of type T. The Parser function is used to parse each value in the comma-separated string obtained from the environment variable. If the environment variable is not set or parsing fails for any of the values, the function returns the fallback value.