Tired of writing the same env helpers over and over again? Yeah. me too. That's why this repo exists.
go get github.com/herzrasen/go-env
To get an error when no environment variable key
exists:
import "github.com/herzrasen/go-env/env"
v, err := env.GetOrError("FOO")
if err != nil {
return err
}
fmt.Printf("%s", v)
To either load the environment variable or use a default value:
import "github.com/herzrasen/go-env/env"
v := env.GetOrElse("FOO", "baz")
fmt.Printf("%s", v)