如何使用特定的环境值运行go-get命令



我想在GOPROXY='direct'时运行go-get命令,我已经尝试使用VS代码终端运行此命令:

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不会被正确解释为:设置变量并执行继承其环境变量(包括一个集(的命令。

最新更新