如何在特定环境值下运行”go get”命令?

huangapple go评论76阅读模式
英文:

how to run a go get command with certain environment values?

问题

GOPROXY='direct'时,我想运行一个go get命令。我尝试在VS Code终端中运行以下命令:

GOPROXY='direct' go get go.mongodb.org/mongo-driver/mongo

但是我遇到了以下错误:

GOPROXY=direct : 无法将“GOPROXY=direct”识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。
At line:1 char:1
+ GOPROXY='direct' go get go.mongodb.org/mongo-driver/mongo
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (GOPROXY=direct:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

我还尝试了以下命令:

go env set GOPROXY='direct'

但是当我运行go env命令时,GOPROXY的值仍然是这样的:GOPROXY=https://proxy.golang.org,direct。我还尝试在Windows环境变量中定义一个GOPROXY变量,并将其值设置为direct,但它也无法完成任务。

英文:

I want to run a go get command when GOPROXY='direct', I've tried to run this command using the VS code terminal:

GOPROXY='direct' go get go.mongodb.org/mongo-driver/mongo

but I'm getting this error:

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

I've also tried:

go env set GOPROXY='direct'

but when I run go env command the GOPROXY value is still like this GOPROXY=https://proxy.golang.org,direct
and I also tried to define a GOPROXY variable in the windows environment variable and giving it the value of direct but it also failed to do the job.

答案1

得分: 2

请确保你的VSCode终端是bash终端,而不是CMD或Powershell。

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

英文:

Make sure your VSCode terminal is a bash one, not a CMD or Powershell.

In a CMD or Powershell, the syntax var=xxx cmd would not be correctly interpreted as: set a variable and execute a command inheriting its environment variables, including the one set.

huangapple
  • 本文由 发表于 2021年12月14日 18:13:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/70347135.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定