Documentation
¶
Overview ¶
Package env has simple functions for environment variables manipulation
Index ¶
- func As[T any](envKey string, parser func(string) (T, error)) (T, error)
- func AsDefault[T any](envKey string, defaultVal T, parser func(string) (T, error)) (T, error)
- func Bool(envKey string) (bool, error)
- func BoolDefault(envKey string, defaultVal bool) (bool, error)
- func Duration(envKey string) (time.Duration, error)
- func DurationDefault(envKey string, defaultVal time.Duration) (time.Duration, error)
- func EnvAsBool(envKey string, defaultVal bool) booldeprecated
- func EnvAsInt(envKey string, defaultVal int) intdeprecated
- func EnvOrDefault(envKey, defaultVal string) stringdeprecated
- func Int(envKey string) (int, error)
- func IntDefault(envKey string, defaultVal int) (int, error)
- func MustAs[T any](envKey string, parser func(string) (T, error)) T
- func MustBool(envKey string) bool
- func MustDuration(envKey string) time.Duration
- func MustEnv(envKey string) stringdeprecated
- func MustEnvAsBool(envKey string) booldeprecated
- func MustEnvAsInt(envKey string) intdeprecated
- func MustInt(envKey string) int
- func MustString(envKey string) string
- func MustStringSplice(envKey string, sep string) []string
- func String(envKey string) (string, error)
- func StringDefault(envKey string, defaultVal string) (string, error)
- func StringSplice(envKey string, sep string) ([]string, error)
- func StringSpliceDefault(envKey string, sep string, defaultVal []string) ([]string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶ added in v0.2.0
As returns the value of the environment variable envKey parsed as T using parser. Returns an error if the variable is not set (eq "") or parser returns an error. parser must be a function of the form func(string) (T, error).
func AsDefault ¶ added in v0.2.0
AsDefault returns the value of the environment variable envKey parsed as T using parser. If the variable is not set (eq ""), it returns defaultVal and a nil error. Returns an error if parser returns an error for the raw string value. parser must be a function of the form func(string) (T, error).
func Bool ¶ added in v0.2.0
Bool returns the value of the environment variable envKey as a bool. Returns an error if the variable is not set (eq "") or cannot be parsed as a bool. Parsing is delegated to strconv.ParseBool.
func BoolDefault ¶ added in v0.2.0
BoolDefault returns the value of the environment variable envKey as a bool. If the variable is not set (eq ""), it returns defaultVal and a nil error. Parsing is delegated to strconv.ParseBool, which accepts: 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Returns an error for any other value.
func Duration ¶ added in v0.2.0
Duration returns the value of the environment variable envKey as a time.Duration. Returns an error if the variable is not set (eq "") or cannot be parsed as a duration. Parsing is delegated to time.ParseDuration. Valid units: ns, us (or µs), ms, s, m, h.
func DurationDefault ¶ added in v0.2.0
DurationDefault returns the value of the environment variable envKey as a time.Duration. If the variable is not set (eq ""), it returns defaultVal and a nil error. Parsing is delegated to time.ParseDuration. Valid units: ns, us (or µs), ms, s, m, h. Returns an error if the value cannot be parsed as a duration.
func EnvOrDefault
deprecated
func Int ¶ added in v0.2.0
Int returns the value of the environment variable envKey as an int. Returns an error if the variable is not set (eq "") or cannot be parsed as an integer.
func IntDefault ¶ added in v0.2.0
IntDefault returns the value of the environment variable envKey as an int. If the variable is not set (eq ""), it returns defaultVal and a nil error. Returns an error if the value cannot be parsed as an integer.
func MustAs ¶ added in v0.2.0
MustAs returns the value of the environment variable envKey parsed as T using parser. Panics if the variable is not set (eq "") or parser returns an error. parser must be a function of the form func(string) (T, error).
func MustBool ¶ added in v0.2.0
MustBool returns the value of the environment variable envKey as a bool. Panics if the variable is not set (eq "") or cannot be parsed as a bool. Parsing is delegated to strconv.ParseBool.
func MustDuration ¶ added in v0.2.0
MustDuration returns the value of the environment variable envKey as a time.Duration. Panics if the variable is not set (eq "") or cannot be parsed as a duration. Parsing is delegated to time.ParseDuration. Valid units: ns, us (or µs), ms, s, m, h.
func MustEnvAsBool
deprecated
func MustEnvAsInt
deprecated
func MustInt ¶ added in v0.2.0
MustInt returns the value of the environment variable envKey as an int. Panics if the variable is not set (eq "") or cannot be parsed as an integer.
func MustString ¶ added in v0.2.0
MustString returns the value of the environment variable envKey as a string. Panics if the variable is not set (eq "").
func MustStringSplice ¶ added in v0.2.0
MustStringSplice returns the value of the environment variable envKey split into a []string using sep as the delimiter. Panics if the variable is not set (eq ""). No trimming or filtering of elements is applied; the raw strings.Split result is returned.
func String ¶ added in v0.2.0
String returns the value of the environment variable envKey as a string. Returns an error if the variable is not set (eq "").
func StringDefault ¶ added in v0.2.0
StringDefault returns the value of the environment variable envKey as a string. If the variable is not set (eq ""), it returns defaultVal and a nil error. A non-empty value is always returned without error regardless of its content.
func StringSplice ¶ added in v0.2.0
StringSplice returns the value of the environment variable envKey split into a []string using sep as the delimiter. Returns an error if the variable is not set (eq ""). No trimming or filtering of elements is applied; the raw strings.Split result is returned.
func StringSpliceDefault ¶ added in v0.2.0
StringSpliceDefault returns the value of the environment variable envKey split into a []string using sep as the delimiter. If the variable is not set (eq ""), it returns defaultVal and a nil error. No trimming or filtering of elements is applied; the raw strings.Split result is returned.
Types ¶
This section is empty.