Today I Learned
Search…
Reading & Setting Environment variables in Go
Use os.Getenv() and os.Setenv() for reading and setting environment variables.

Demo

1
package main
2
​
3
import (
4
"fmt"
5
"os"
6
)
7
​
8
func main() {
9
os.Setenv("NAME", "gopher")
10
​
11
fmt.Printf("My Desktop Environment : %s.\n", os.Getenv("XDG_CURRENT_DESKTOP"))
12
}
Copied!
Copy link
Edit on GitHub
Contents
Demo