1.获取所有的环境变量[os.Environ]
package main import ( "fmt" "os" "strings" ) func main(){ envs:=os.Environ(); for _,env:=range envs { cache:= strings.Split(env,"="); fmt.Printf("key=%v value=%v\n",cache[0],cache[1]); } }
2.获取环境变量
package main import ( "fmt" "os" ) func main(){ path:=os.Getenv("GOPATH"); fmt.Println(path); }
3.设置环境变量
原文:https://www.cnblogs.com/zh718594493/p/14177272.html