Golang 依赖包下载时候代理设置

版权声明:无私奉献,希望大家转载注明出处,谢谢! 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

错误信息

参考地址

https://github.com/golang/go/wiki/GoGetProxyConfig
https://github.com/Microsoft/vscode-go/issues/653

猜你喜欢

转载自blog.csdn.net/littlebrain4solving/article/details/78871137