goproxy.cn解决go get 失败问题

作者: root007 分类: 未分类 发布时间: 2019-09-10 17:22

 go get golang.org/x 包失败

“golang.org/x/sys/windows” (https fetch: Get https://golang.org/x/sys/windows?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)

https://github.com/goproxy/goproxy.cn


GOPROXY 环境变量

Go 1.13 及以上(推荐)

打开你的终端并执行:

$ go env -w GOPROXY=https://goproxy.cn,direct

完成。

macOS 或 Linux

打开你的终端并执行:

$ export GOPROXY=https://goproxy.cn

或者

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

完成。

Windows

打开你的 PowerShell 并执行:

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

不过,需要依赖于 go module 功能。可通过 export GO111MODULE=on 开启 MODULE。

如果项目不在 GOPATH 中,则无法使用 go get ...,但可以使用 go mod ... 相关命令。

也可以通过置空这个环境变量来关闭,export GOPROXY=

批话那么其实只需要:

go env -w GOPROXY=https://goproxy.cn,direct
go env -w  GO111MODULE=on

go get github.com/prometheus/client_golang/prometheus/promhttp
go: finding github.com/prometheus/client_golang v1.1.0
go: downloading github.com/prometheus/client_golang v1.1.0
go: extracting github.com/prometheus/client_golang v1.1.0
go: downloading github.com/prometheus/common v0.6.0
go: downloading github.com/prometheus/procfs v0.0.3
go: downloading github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90
go: downloading github.com/beorn7/perks v1.0.1

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注