手动下载并放置一个 golang mod 文件

Manually Download and Place a golang mod file

我在中国,正在linux上编写程序。问题是golang相关的东西在国内被屏蔽了。我尝试了很多代理,但找不到解决方案。有人可以向我解释手动放置此文件的位置吗?我可以在浏览器中打开它,但我不知道把它放在哪里。

go: github.com/onsi/gomega@v1.17.0: 获取“https://proxy.golang.org/github.com/onsi/gomega/@v/v1.17.0.mod": 拨号 tcp 172.217.163.49:443: i/o 超时 开始:下载 github.com/pkg/errors v0.9.1

使用代理的例子,可以参考这个repo which is used for china Gophers and you can check the documentation on this site。你可以使用另一个代理 link 但方法是一样的。

  • macOS 或 Linux

打开终端并执行

$ export GO111MODULE=on
$ export GOPROXY=https://goproxy.cn

$ echo "export GO111MODULE=on" >> ~/.profile
$ echo "export GOPROXY=https://goproxy.cn" >> ~/.profile
$ source ~/.profile

完成。

  • Windows

打开您的 PowerShell 并执行

C:\> $env:GO111MODULE = "on"
C:\> $env:GOPROXY = "https://goproxy.cn"

如果你想破例可以尝试:-

# Set the GOPROXY environment variable
export GOPROXY=https://goproxy.io,direct
# Set environment variable allow bypassing the proxy for specified repos (optional)
export GOPRIVATE=git.mycompany.com,github.com/my/private