运行
go build xxx.go
错误信息
go: golang.org/x/sys@v0.0.0-20180905080454-ebe1bf3edb33: unrecognized import path "golang.org/x/sys" (https fetch: Get https://golang.org/x/sys?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: google.golang.org/appengine@v1.5.0: unrecognized import path "google.golang.org/appengine" (https fetch: Get https://google.golang.org/appengine?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: golang.org/x/tools@v0.0.0-20190328211700-ab21143f2384: unrecognized import path "golang.org/x/tools" (https fetch: Get https://golang.org/x/tools?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: golang.org/x/net@v0.0.0-20181114220301-adae6a3d119a: unrecognized import path "golang.org/x/net" (https fetch: Get https://golang.org/x/net?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: golang.org/x/crypto@v0.0.0-20190308221718-c2843e01d9a2: unrecognized import path "golang.org/x/crypto" (https fetch: Get https://golang.org/x/crypto?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: golang.org/x/net@v0.0.0-20180911220305-26e67e76b6c3: unrecognized import path "golang.org/x/net" (https fetch: Get https://golang.org/x/net?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: golang.org/x/crypto@v0.0.0-20181127143415-eb0de9b17e85: unrecognized import path "golang.org/x/crypto" (https fetch: Get https://golang.org/x/crypto?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: golang.org/x/crypto@v0.0.0-20180904163835-0709b304e793: unrecognized import path "golang.org/x/crypto" (https fetch: Get https://golang.org/x/crypto?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: golang.org/x/sys@v0.0.0-20190222072716-a9d3bda3a223: unrecognized import path "golang.org/x/sys" (https fetch: Get https://golang.org/x/sys?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: cloud.google.com/go@v0.37.4: unrecognized import path "cloud.google.com/go" (https fetch: Get https://cloud.google.com/go?go-get=1: dial tcp 172.217.31.238: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: error loading module requirements
其他
运行的程序是 https://github.com/chenhg5/go...
请问这些错误是怎么回事呀?
golang.org是谷歌的, 所以被墙, 我还能说什么...
搬上知乎的一个答案
第一个方法:
由于这两个网站在 github 上都有一个同步仓库,分别在 http://github.com/golang 和 http://github.com/kubernetes 所以比较笨的方法就是去下载 github 上对应的代码,然后在手动把目录名改回去,这样 golang 就可以认了。但是这种做法一来比较麻烦,二来升级库的时候会很麻烦,三来很多自动化的依赖管理工具就不能用了,所以大的项目并不推荐这么搞。
第二个方法:
glide 算是一个还比较流行的 golang 依赖管理,他提供了一个 mirror 的命令,可以进行自动的 package 地址替换,比如我想下载 http://golang.org/x/net 那么先敲一个
glide mirror set https://golang.org/x/net https://github.com/golang/net --vcs git
可以在 ~/.glide/mirror.yaml 里看到所有进行 mirror 的 pacakge 这样就可以进行自动的地址替换。所有 http://golang.org 和 http://k8s.io 的库都加进来就可在下载的时候进行自动替换了。
不过 glide mirror 有一个问题就是无法正确的处理 subpackage 比如我想下载 http://golang.org/x/net/http2 这个 mirror 就没有办法设置了,设置成 http://github.com/golang/net 会把这个项目覆盖到 http2 目录,设置为 http://github.com/golang/net/... 又会报找不到 vcs 文件信息。
第三个方法:
也就是终极方法,使用一个我国程序员 patch 过的一个 glide 版本(大概国外人都没这个需求),给 mirror 命令新加了一个 base 参数,上面的例子通过 glide mirror set https://golang.org/x/net/http2 https://github.com/golang/net --base golang.org/x/net --vcs git 就可以解决了
具体的配置信息可以点击xkeyideal/glide,看看作者自己的一个 README。
希望经过这番折腾,可以让你写代码的时候心情好一点点。
参考
https://zhuanlan.zhihu.com/p/...