2

我想运行 go get 命令时GOPROXY='direct',我尝试使用 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但它也未能完成这项工作。

4

1 回答 1

2

确保您的 VSCode 终端是一个终端bash,而不是 CMD 或 Powershell。

在 CMD 或 Powershell 中,语法var=xxx cmd不会被正确解释为:设置变量并执行继承其环境变量的命令,包括一组。

于 2021-12-15T08:27:17.550 回答