版权声明:无私奉献,希望大家转载注明出处,谢谢! https://blog.csdn.net/littlebrain4solving/article/details/78871137
说明
我们在使用 Go 下载依赖时候经常遇到网络环境的问题,如:golang.org
站点必须要翻墙才可以进行下载;而单单设置系统层面的 http_proxy
有时也不能完全解决问题,所以我记录了我尝试过的解决方案 - 必须要设置两种代理方式才行(仓库代理与系统代理),具体参考下面的使用。
切记两种代理必须要同时设置才可起作用;吐槽一下:这种方式好蛋疼。
仓库代理
Git
git config [--global] http.proxy http://proxy.example.com:port
Mercurial
编辑 ~/.hgrc
文件并加入以下内容:
[http_proxy]
host=proxy.example.com:port
SVN
编辑 ~/.subversion/servers
文件并加入以下内容:
[Global]
http-proxy-host=proxy.example.com
http-proxy-port=xxxx
系统代理
局部
参考下面命令,这个设置只是一次性的。
http_proxy=http://127.0.0.1:1087 go get -u -v github.com/golang/lint/golint
全局
在 ~/.bash_profile
文件并加入以下内容:
export http_proxy=proxy.example.com:port
错误信息
- fatal: unable to access ‘https://go.googlesource.com/tools/‘: Failed to connect to go.googlesource.com port 443: Operation timed out
- https fetch failed: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1:443: i/o timeout
- unrecognized import path “golang.org/x/tools/go/buildutil” (https fetch: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
参考地址
https://github.com/golang/go/wiki/GoGetProxyConfig
https://github.com/Microsoft/vscode-go/issues/653