import "github.com/caitlinelfring/go-env-default"
A collection of helper go functions for accessing the value of environment variables with pre-defined default values, including type conversion.
Supports the following types:
string
bool
int
int64
float64
time.Duration
Supported Go versions:
- 1.17
- 1.16
- 1.15
Example:
package main
import (
"fmt"
env "github.com/caitlinelfring/go-env-default"
)
func main() {
fmt.Println(env.GetDefault("MY_ENV_VAR", "foo"))
}
$ go run main.go
foo
$ MY_ENV_VAR=bar go run main.go
bar