A small package that gets environment variables and convert them to their purposed basic type. If invalid or unset, use the fallback value.
API and detailed documentation can be found at https://godoc.org/github.com/Kansuler/env
go get github.com/Kansuler/env
import "github.com/Kansuler/env"
func main() {
// get environment variable `test_environment` as bool, if not set use fallback value
testEnv := env.Bool("test_environment", false)
if testEnv {
// Do test env stuff...
}
}
func Bool(key string, fallback bool) bool
func String(key string, fallback string) string
func Bytes(key string, fallback []byte) []byte
func Runes(key string, fallback []rune) []rune
func Float32(key string, fallback float32) float32
func Float64(key string, fallback float64) float64
func Int(key string, fallback int) int
func Int8(key string, fallback int8) int8
func Int16(key string, fallback int16) int16
func Int32(key string, fallback int32) int32
func Int64(key string, fallback int64) int64
func Uint(key string, fallback uint) uint
func Uint8(key string, fallback uint8) uint8
func Uint16(key string, fallback uint16) uint16
func Uint32(key string, fallback uint32) uint32
func Uint64(key string, fallback uint64) uint64
func Uintptr(key string, fallback uintptr) uintptr
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.