A Go (golang) port of the node env-utils project.
Easily Get Environment Variables
go get github.com/BolajiOlajide/go-env-utils
gets an environment variable
import "github.com/BolajiOlajide/go-env-utils"
// load .env file and fail silently if it doesn't exist
_ := env.InitializeEnv()
PORT := env.GetEnvVar("PORT", nil)
You can force the value to be a boolean
options := env.Options{
Boolean: true
}
PORT := env.GetEnvVar("PORT", options)
And if your env variable is a comma separated string you can get back an array instead
options := env.Options{
CommaSeparated: true
}
PORT := env.GetEnvVar("PORT", options)
You can also set a fallback value for development mode
options := env.Options{
DevDefault: "1234"
}
PORT := env.GetEnvVar("PORT", options)