【问题标题】:how to run a go get command with certain environment values?如何运行具有某些环境值的 go get 命令?
【发布时间】:2022-01-17 15:53:16
【问题描述】:

我想在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 的值,但它也未能完成这项工作。

【问题讨论】:

  • 你会发送“go env”命令的输出吗?

标签: windows go visual-studio-code environment-variables goproxy


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2010-11-24
    • 2017-07-10
    • 2020-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-26
    • 2021-05-27
    相关资源
    最近更新 更多