envutil

package
v1.0.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2025 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetenvWithDefault

func GetenvWithDefault(envKey, defValue string) string

GetenvWithDefault - returns the env if specified, default value otherwise

func RequiredEnv

func RequiredEnv(envKey string) (string, error)

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

func RevokableSetenv(envKey, envValue string) (func() error, error)

RevokableSetenv ...

func RevokableSetenvs

func RevokableSetenvs(envs map[string]string) (func() error, error)

RevokableSetenvs ...

func SetenvForFunction

func SetenvForFunction(envKey, envValue string, fn func()) error

SetenvForFunction ...

func SetenvsForFunction

func SetenvsForFunction(envs map[string]string, fn func()) error

SetenvsForFunction ...

func StringFlagOrEnv

func StringFlagOrEnv(flagValue *string, envKey string) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL