Skip to content

Repository files navigation

env

simple env vars, checks if the env var exists or returns the zero value

credit goes to https://github.com/17twenty for initial authoring

Go Report CardGo Reference

Basic use

env:=env.GetAsString("ENV", "dev")
isFlagEnabled:=env.GetAsBool("FEATURE_ONE")
allowList:=env.GetAsSlice("ALLOW_LIST", ",")

Load env file

LoadEnvFile("./.env.local")
foo:=env.GetAsString("ENV", "dev")

Strict mode

env.WithStrictMode()
// ENV goes not exist// panicsfoo:=env.GetAsString("ENV")

With defaults

env.WithStrictMode()
// ENV goes not exist, returns barfoo:=env.GetAsStringWithDefault("ENV", "bar")
env.WithStrictMode()
// ENV goes not exist, returns 1foo:=env.GetAsIntWithDefault("ENV", 1)

About

simple env vars

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages