Documentation ¶
Overview ¶
Package env provides utility functions for loading environment variables with default values.
A common use of the env package is for combining flag with environment variables in a Go program.
Example:
func main() { var ( flProject = flag.String("http.addr", env.String("HTTP_ADDRESS", ":https"), "HTTP server address") ) flag.Parse() }
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Bool returns the environment variable value specified by the key parameter, otherwise returning a default value if set.
func Int ¶
Int returns the environment variable value specified by the key parameter, otherwise returning a default value if set.
func String ¶
String returns the environment variable value specified by the key parameter, otherwise returning a default value if set.
Example ¶
package main import ( "fmt" "os" "github.com/micromdm/go4/env" ) func main() { addr := env.String("HTTP_ADDRESS", ":https") fmt.Printf("addr1: %s\n", addr) os.Setenv("HTTP_ADDRESS", "127.0.0.1:8080") addr = env.String("HTTP_ADDRESS", ":https") fmt.Printf("addr2: %s\n", addr) }
Output: addr1: :https addr2: 127.0.0.1:8080
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.