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

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

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超时
go: 正在下载github.com/pkg/errors v0.9.1

英文:

I am in China and I am compiling a program on linux. The problem is that golang related things are blocked in China. I have tried many proxies but I can't find a solutuion. Can some one please explain me where to manually put this file. I can open it in browser but i don' know where to place it.

go: github.com/onsi/gomega@v1.17.0: Get "https://proxy.golang.org/github.com/onsi/gomega/@v/v1.17.0.mod": dial tcp 172.217.163.49:443: i/o timeout
go: downloading github.com/pkg/errors v0.9.1

答案1

得分: 4

使用代理的示例,您可以参考这个仓库,该仓库用于中国的Gophers,并且您可以在这个网站上查看文档。您可以使用其他代理链接,但方法是相同的。

  • 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"

如果您想要设置例外情况,可以尝试:

# 设置GOPROXY环境变量
export GOPROXY=https://goproxy.io,direct
# 设置允许绕过代理的环境变量,用于指定的仓库(可选)
export GOPRIVATE=git.mycompany.com,github.com/my/private
英文:

As an example to use a proxy, you can refer to this repo which is used for china Gophers and you can check the documentation on this site. you may use another proxy link but the method is the same.

  • macOS or Linux

Open your terminal and execute

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

or

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

done.

  • Windows

Open your PowerShell and execute

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

if you want to make exceptions you can try:-

# 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

答案2

得分: 0

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

这对我有效。非常感谢。

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

This works for me. Thanks a lot.

huangapple
  • 本文由 发表于 2022年3月18日 07:43:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/71520300.html
匿名

发表评论

匿名网友

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

确定