go获取环境变量

package main

import (
	"fmt"
	"os"
)

func main() {
	var goos string = os.Getenv("GOPATH")
	fmt.Printf("The operating system is: %s\n", goos)
	path := os.Getenv("PATH")
	fmt.Printf("The PATH is: %s\n", path)
}


输出:

The operating system is: D:\GoPath
The PATH is: C:\windows\SysWOW64;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;D:\mysql5.6\bin;D:\python3.64\anzhuangweizhi;C:\windows\system32;D:\Sublime Text 3 Build installed\Sublime Text 3;D
:\python3.64\anzhuangweizhi\Lib\site-packages\django\bin;C:\Program Files\nodejs\;D:\python2.7\Python2.7_Install;C:\Program Files\Common Files\Intel\WirelessCommon\;E:\Redis\;E:\Git\cmd;C:\Program Files\Docker Toolbox\;C:\Progra
m Files\Oracle\VirtualBox\;D:\RabbitMQ\erlang\erl10.0.1\bin;D:\RabbitMQ\erlang\erl10.0.1\bin;D:\RabbitMQ\rabbitmq_server-3.7.7\sbin;F:\MongoDB\installed_location\bin;D:\Go\bin;D:\GoPath\bin;D:\vscode\Microsoft VS Code\bin;D:\Ope
nSSL\OpenSSL-Win64\bin;C:\Users\Administrator\AppData\Roaming\npm\cnpm;C:\Users\Administrator\AppData\Roaming\npm\supervisor;D:\Anaconda\Installed\condabin;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\Wir
elessCommon\;E:\Redis\;C:\Program Files\Docker Toolbox\;C:\Program Files\Oracle\VirtualBox\;D:\prometheus\prometheus-2.33.3.windows-amd64;D:\GoPath\bin;D:\go\bin
posted @ 2022-02-26 23:13  ty1539  阅读(128)  评论(0编辑  收藏  举报