Categorygithub.com/code-gorilla-au/env
repositorypackage
1.1.1
Repository: https://github.com/code-gorilla-au/env.git
Documentation: pkg.go.dev

# README

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 Card Go 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
// panics
foo := env.GetAsString("ENV")

With defaults


env.WithStrictMode()

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


env.WithStrictMode()

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