os.LookupEnv

The Go function that returns an environment variable's value and a boolean saying whether it was set at all.

In more detail

Use the comma ok result to tell a missing variable from one set to an empty string. It is the building block of an environment fallback such as envOr. Prefer it over os.Getenv whenever absent needs its own behaviour.

Example

if v, ok := os.LookupEnv("PROBE_DEBUG"); ok {
	fmt.Println("debug:", v)
}

Related terms

Taught in

References