# README
go-env-default
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
Usage
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
# Functions
GetBoolDefault returns the boolean value of the environment variable, or a default value if the environment variable is not defined or is an empty string.
GetDefault returns the string value of the environment variable, or a default value if the environment variable is not defined or is an empty string.
GetDurationDefault returns the time.Duration value of the environment variable, or a default value if the environment variable is not defined or is an empty string.
GetFloatDefault returns the float64 value of the environment variable, or a default value if the environment variable is not defined or is an empty string.
GetInt64Default returns the int64 value of the environment variable, or a default value if the environment variable is not defined or is an empty string.
GetIntDefault returns the int value of the environment variable, or a default value if the environment variable is not defined or is an empty string.