Documentation
¶
Index ¶
- func GetenvWithDefault(envKey, defValue string) string
- func RequiredEnv(envKey string) (string, error)
- func RevokableSetenv(envKey, envValue string) (func() error, error)
- func RevokableSetenvs(envs map[string]string) (func() error, error)
- func SetenvForFunction(envKey, envValue string, fn func()) error
- func SetenvsForFunction(envs map[string]string, fn func()) error
- func StringFlagOrEnv(flagValue *string, envKey string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetenvWithDefault ¶
GetenvWithDefault - returns the env if specified, default value otherwise
func RequiredEnv ¶
RequiredEnv - returns the env's value if specified, otherwise it returns an error that explains the key is required. Use this function to reduce error prone code duplication. E.g. instead of doing this in your code:
myVar1 := os.Getenv("MY_ENV1") if len(myVar1) < 1 { return nil, errors.New("MY_ENV1 required") }
You can use this function like:
myVar1, err := requiredEnv("MY_ENV1") if err != nil { return nil, errors.WithStack(err) }
In the first example you have to specify myVar1 and MY_ENV1 two times, which can lead to issues if you copy-paste that code but e.g. forget to change the var name in the
if len(myVar1) < 1
line, or if you forget to change the var key in the error message/string.
func RevokableSetenv ¶
RevokableSetenv ...
func RevokableSetenvs ¶
RevokableSetenvs ...
func SetenvForFunction ¶
SetenvForFunction ...
func SetenvsForFunction ¶
SetenvsForFunction ...
func StringFlagOrEnv ¶
StringFlagOrEnv - returns the value of the flag if specified, otherwise the env's value. Empty string counts as not specified!
Types ¶
This section is empty.