我想在 GOPROXY='direct'
时运行 go get 命令,我尝试使用 VS code 终端运行此命令:
GOPROXY='direct' go get go.mongodb.org/mongo-driver/mongo
但我收到此错误:
GOPROXY=direct : The term 'GOPROXY=direct' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ GOPROXY='direct' go get go.mongodb.org/mongo-driver/mongo
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (GOPROXY=direct:String) [], CommandNotFoundEx
ception
+ FullyQualifiedErrorId : CommandNotFoundException
我也尝试过:
go env set GOPROXY='direct'
但是当我运行go env
命令时,GOPROXY
值仍然是这样的GOPROXY=https://proxy.golang.org,direct
我还尝试在 Windows 环境变量中定义一个 GOPROXY 变量并为其赋予 direct
值,但它也未能完成这项工作。
最佳答案
确保您的 VSCode 终端是 bash
终端,而不是 CMD 或 Powershell。
在 CMD 或 Powershell 中,语法 var=xxx cmd
不会被正确解释为:设置变量并执行继承其环境变量(包括一组设置)的命令。
关于windows - 如何使用特定环境值运行 go get 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70347135/