Skip to content

Go helper functions for accessing environment variables with defaults

License

Notifications You must be signed in to change notification settings

caitlinelfring/go-env-default

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-env-default

Go Reference Go Report Card codecov Go Tests GitHub go.mod Go version

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

About

Go helper functions for accessing environment variables with defaults

Topics

Resources

License

Stars

Watchers

Forks

Languages