-
go env :查看终端运行环境
PS H:\go_workspace> go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOENV=C:\Users\Administrator\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=H:\go_workspace
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=E:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=E:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\go-build672771602=/tmp/go-build -gno-record-gcc-switches
-
go help env :查看 go env 帮助命令
PS H:\go_workspace> go help env
usage: go env [-json] [-u] [-w] [var ...]
Env prints Go environment information.
By default env prints information as a shell script
(on Windows, a batch file). If one or more variable
names is given as arguments, env prints the value of
each named variable on its own line.
The -json flag prints the environment in JSON format
instead of as a shell script.
The -u flag requires one or more arguments and unsets
the default setting for the named environment variables,
if one has been set with 'go env -w'.
The -w flag requires one or more arguments of the
form NAME=VALUE and changes the default settings
of the named environment variables to the given values.
For more about environment variables, see 'go help environment'.
-
go env xxx :查看指定配置
PS H:\go_workspace> go env GOPATH
H:\go_workspace
-
go env -json : 以json格式输出配置
PS H:\go_workspace> go env -json
{
"AR": "ar",
"CC": "gcc",
"CGO_CFLAGS": "-g -O2",
"CGO_CPPFLAGS": "",
"CGO_CXXFLAGS": "-g -O2",
"CGO_ENABLED": "1",
"CGO_FFLAGS": "-g -O2",
"CGO_LDFLAGS": "-g -O2",
"CXX": "g++",
"GCCGO": "gccgo",
"GO111MODULE": "on",
"GOARCH": "amd64",
"GOBIN": "",
"GOCACHE": "C:\\Users\\Administrator\\AppData\\Local\\go-build",
"GOENV": "C:\\Users\\Administrator\\AppData\\Roaming\\go\\env",
"GOEXE": ".exe",
"GOFLAGS": "",
"GOGCCFLAGS": "-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\go-build952984822=/tmp/go-build -gno-record-gcc-switches",
"GOHOSTARCH": "amd64",
"GOHOSTOS": "windows",
"GOINSECURE": "",
"GOMOD": "NUL",
"GONOPROXY": "",
"GONOSUMDB": "",
"GOOS": "windows",
"GOPATH": "H:\\go_workspace",
"GOPRIVATE": "",
"GOPROXY": "https://goproxy.cn,direct",
"GOROOT": "E:\\go",
"GOSUMDB": "sum.golang.org",
"GOTMPDIR": "",
"GOTOOLDIR": "E:\\go\\pkg\\tool\\windows_amd64",
"PKG_CONFIG": "pkg-config"
}
PS H:\go_workspace>
-
go env -w xxx : 设置env
PS H:\go_workspace> go env -w GO111MODULE=on
-
go env -u GOPROXY : 取消env配置
PS H:\go_workspace> go env -u GOPROXY
-
go env -w GOPROXY=https://goproxy.cn,direct 在win的cmd下和vscode的终端中执行效果不一致
在vscode中报错:
H:\go_workspace> go env -w GOPROXY=https://goproxy.cn,direct
go env -w: arguments must be KEY=VALUE: invalid argument: direct
在win下的cmd中执行成功:
H:\go_workspace>go env -w GOPROXY=https://goproxy.cn,direct
网友评论