os.Getenv
The Go function that returns the value of an environment variable, or an empty string if it is not set.
In more detail
It cannot tell unset from set to empty; use os.LookupEnv when that matters. Environment variables are the usual way containers and pipelines pass settings to a program.
Example
fmt.Println("timeout:", os.Getenv("PROBE_TIMEOUT"))Related terms
- os.LookupEnv — The Go function that returns an environment variable's value and a boolean saying whether it was set at all.
- environment variable — A named setting such as PORT=8000 that a program reads from its surroundings when it starts.
- environment fallback — Using an environment variable as a default for a setting, while still letting an explicit command-line flag override it.
Taught in
- Installing the Go Toolchain — Concurrent Systems Programming with Go
- Files and the os Package — Concurrent Systems Programming with Go
- Parsing Arguments with flag — Concurrent Systems Programming with Go