I know Python can do it, but I can't figure it out using Go. os.Setenv("NAME", "Flavio") os.Unsetenv() unsets an environment variable. In golang, how do you assign a default value if an environment variable isn't set? A language needs only one conditional control flow construct. Use os.LookupEnv() to be able to do that. how to check the value of GOGC / GC percentage ? It is often asked why Go does not have a ternary operator. Contribute to golang/go development by creating an account on GitHub. We know that the default value for GOGC is 100. os.Getenv() gets an environment variable. Configuring Golang Applications Using Environment Variables. It’s not possible to determine not set or empty. Parsing environment variables with Go is simple, thanks to the standard library os package. The Go programming language. is there a way to get the path of a folder using Windows Recognized Environment Variables values with Go?. The Go FAQ says, The if-else form, although longer, is unquestionably clearer. Go env is not printing the GOGC value. But how will get the value from the command prompt. Both are read from environment variables and set to some default value if not present. name := os.Getenv("NAME") os.Setenv() sets an environment variable. I tried an if statement based on os.Getenv being empty, but that doesn't seem to work due to the scope of variable assignment within an if statement. In python I could do mongo_password = os.getenv('MONGO_PASS', 'pass') where pass is the default value if MONGO_PASS env var isn't set..