使用 go get 下载包时,可以加 -v 参数查看下载进度。

虽然有时候设置了 GORPOXY 环境变量,有些包仍会下载失败,报 package xxx: exit status 128 的错误。比如我在下载 Gin 框架时,报错:

PS C:\Users\YangDX> $env:GOPROXY = "https://goproxy.cn"
PS C:\Users\YangDX> go get -v -u github.com/gin-gonic/gin
github.com/gin-gonic/gin (download)
github.com/gin-contrib/sse (download)
github.com/go-playground/validator (download)
github.com/go-playground/universal-translator (download)
github.com/go-playground/locales (download)
github.com/leodido/go-urn (download)
github.com/golang/protobuf (download)
# cd .; git clone -- https://github.com/golang/protobuf C:\Users\YangDX\go\src\github.com\golang\protobuf
Cloning into 'C:\Users\YangDX\go\src\github.com\golang\protobuf'...
error: RPC failed; curl 56 OpenSSL SSL_read: Connection was reset, errno 10054
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
package github.com/golang/protobuf/proto: exit status 128

上面的提示是 github.com/golang/protobuf 这个包下载失败了,我们可以自行访问 github 项目地址,手动下载 master 分支代码,解压到对应目录 C:\Users\YangDX\go\src\github.com\golang\protobuf

当然,也可以重试上面那个 git clone 指令,但由于墙的存在,可能很慢或依旧下载失败。

如果你有翻墙代理的话,可以给 git 设置 http 代理,再去执行 go get 指令,失败的概率就很小了:

# git 设置 http 代理:
git config --global http.proxy http://127.0.0.1:8888

# git 取消 http 代理:
git config --global --unset http.proxy