22 lines
398 B
Go
22 lines
398 B
Go
package env
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func Env() {
|
|
os.Setenv("GOBYEXAMPLE", "WORKS")
|
|
fmt.Println("$GOBYEXAMPLE=", os.Getenv("GOBYEXAMPLE"))
|
|
envGoRoot := os.Getenv("GOROOT")
|
|
fmt.Println("$GOROOT=", envGoRoot)
|
|
|
|
fmt.Println()
|
|
fmt.Println("All env vars:")
|
|
for _, envLine := range os.Environ() {
|
|
pair := strings.SplitN(envLine, "=", 2)
|
|
fmt.Printf("%s=%s\n", pair[0], pair[1])
|
|
}
|
|
}
|