下载golang依赖异常解决
go modules项目执行go build
时异常:
main.go:11:2: module github.com/astaxie/beego: Get "https://proxy.golang.org/github.com/astaxie/beego/@v/list": dial tcp 216.58.200.49: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.
models\task_log.go:12:2: module github.com/astaxie/beego/cache: Get "https://proxy.golang.org/github.com/astaxie/beego/cache/@v/list": dial tcp 216.58.200.49: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.
jobs\job.go:14:2: module github.com/astaxie/beego/logs: Get "https://proxy.golang.org/github.com/astaxie/beego/logs/@v/list": dial tcp 216.58.200.49: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://proxy.golang.org
无法访问。
从 Go 1.11 版本开始,官方支持了 go module 包依赖管理工具。
还新增了 GOPROXY 环境变量。如果设置了该变量,下载源代码时将会通过这个环境变量设置的代理地址,而不再是以前的直接从代码库下载。这无疑对我等无法科学上网的开发良民来说是最大的福音。
使用go env
可以看到,默认的GOPROXY的值是https://proxy.golang.org
。
可喜的是,goproxy.io 这个开源项目帮我们实现好了我们想要的。该项目允许开发者一键构建自己的 GOPROXY 代理服务。同时,也提供了公用的代理服务 https://goproxy.io , 我们只需设置该环境变量即可正常下载被墙的源码包了:export GOPROXY=https://goproxy.io
0
赞
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦