Documentation ¶
Overview ¶
Package env simplifies reading values from environment variables.
It is typically used in the main function to initialize variables from the flag package, then fallback to using environment variables.
Example ¶
package main import ( "flag" "fmt" "github.com/olivere/env" ) func main() { var ( // Parse addr from flag, use HTTP_ADDR and ADDR env vars as fallback addr = flag.String("addr", env.String("127.0.0.1:3000", "HTTP_ADDR", "ADDR"), "Bind to this address") ) flag.Parse() fmt.Println(*addr) }
Output: 127.0.0.1:3000
Index ¶
- func Bool(defaultValue bool, envvars ...string) bool
- func Duration(defaultValue time.Duration, envvars ...string) time.Duration
- func Float32(defaultValue float32, envvars ...string) float32
- func Float64(defaultValue float64, envvars ...string) float64
- func Int(defaultValue int, envvars ...string) int
- func Int64(defaultValue int64, envvars ...string) int64
- func String(defaultValue string, envvars ...string) string
- func Time(defaultValue time.Time, layout string, envvars ...string) time.Time
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Bool inspects the environment variables specified in envvars. If all of these environment variables are empty, it returns defaultValue.
func Duration ¶
Duration inspects the environment variables specified in envvars. If all of these environment variables are empty, it returns defaultValue.
func Float32 ¶
Float32 inspects the environment variables specified in envvars. If all of these environment variables are empty, it returns defaultValue.
func Float64 ¶
Float64 inspects the environment variables specified in envvars. If all of these environment variables are empty, it returns defaultValue.
func Int ¶
Int inspects the environment variables specified in envvars. If all of these environment variables are empty, it returns defaultValue.
func Int64 ¶
Int64 inspects the environment variables specified in envvars. If all of these environment variables are empty, it returns defaultValue.
Types ¶
This section is empty.