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

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

我想在 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/

相关文章:

windows - Windows 7 中非常基本的 git 批处理

go - 为什么我得到 j 0 而不是 777

go - 是否可以将 Go Task runner 配置为使用文件扩展名 yaml?

visual-studio-code - 在 Visual Studio 代码中格式化 Scala 文件

c# - Ubuntu 19.10 上的 Unity3D,带有 vscode 和 C# 扩展 : get an error and the autocomplete doesn't working

node.js - 如何在 vs-code 中设置扩展的默认 Node 读取位置?

c++ - 多线程和多进程应用程序的锁定机制有什么区别?

vb.net - 如何检查输入的日期应该大于 vb.net 中的系统日期

windows - 用于 QA 测试的自动输入工具?回放击键和鼠标点击

xml - golang : Omit name of struct in xml.编码(marshal)