golang go get命令无响应问题
操作
1
|
go get -v github.com/golang/net
|
现象
go get github.com/golang/net: module github.com/golang/net:
Get https://proxy.golang.org/github.com/golang/net/@v/list:
dial tcp 216.58.220.209: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.
原因
所下载的库依赖有官方库,而官方被封禁网导致。
方法
法一:设置代理
1
2
3
|
go env -w GOPROXY=https://goproxy.cn
##设置完后 重新执行即可go get
|
1
2
3
|
ps:
go1.11发布后,还发布一个goproxy提供代理服务,goproxy.cn是专门服务于中国的,依赖于七牛云
github地址: https://github.com/goproxy
|
法二:git clone 依赖包直接到GOPATH/src/下
1
2
|
cd /d %GOPATH%/src/
git clone https://github.com/golang/net.git
|
1
2
|
ps:https://github.com/golang上为golang.org的镜像依赖包
所以,可以直接使用git clone代替go get
|
go get 指令没有反应/出错/超时
使用GitHub上的eclipse/paho.mqtt.golang包时,长时间无响应后,弹出以下错误提示
1
|
$ go get github.com/eclipse/paho.mqtt.golang
|
package golang.org/x/net/proxy: unrecognized import path “golang.org/x/net/proxy” (https fetch: Get https://golang.org/x/net/proxy?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.)
出现这个问题的原因主要还是我们所使用网络的特殊性,导致go get无法拉取我们所需包的源码,从goproxy的官网上的使用分布图就能很明显的看出来:
此时修改一下环境变量启动GOPROXY,再用go get -v即可,-v参数能够显示go get执行的进度
1
2
3
4
|
# Enable the go modules feature
export GO111MODULE=on
# Set the GOPROXY environment variable
export GOPROXY=https://goproxy.io
|
|