Logo

Programming-Idioms

History of Idiom 205 > diff from v18 to v19

Edit summary for version 19 by programming-idioms.org:
[Go] Avoid underscores in snippets

Version 18

2019-10-01, 08:33:31

Version 19

2019-10-01, 08:34:21

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"
Imports
import "os"
Code
_foo, ok := os.LookupEnv("FOO")
if !ok {
	_foo = "none"
}
Code
foo, ok := os.LookupEnv("FOO")
if !ok {
	foo = "none"
}
Doc URL
https://golang.org/pkg/os/#LookupEnv
Doc URL
https://golang.org/pkg/os/#LookupEnv
Demo URL
https://play.golang.org/p/_lcIxJgOcrX
Demo URL
https://play.golang.org/p/agLM0k2eLjV