Logo

Programming-Idioms

History of Idiom 205 > diff from v6 to v7

Edit summary for version 7 by j:
New Go implementation by user [j]

Version 6

2019-09-29, 19:13:14

Version 7

2019-09-29, 19:52:51

Idiom #205 Get an environment variable

Read an environment variable with the name "FOO" and assign it to the string variable foo. If it does not exist or if the system does not support environment variables, assign a value of "none".

Idiom #205 Get an environment variable

Read an environment variable with the name "FOO" and assign it to the string variable foo. If it does not exist or if the system does not support environment variables, assign a value of "none".

Extra Keywords
envvar os system
Extra Keywords
envvar os system
Imports
import "os"
Code
_foo, ok := os.LookupEnv("FOO")
if !ok {
	_foo = "none"
}
Doc URL
https://golang.org/pkg/os/#LookupEnv
Demo URL
https://play.golang.org/p/_lcIxJgOcrX