如何配置go命令以使用代理?
我想运行go install
来安装游览,但是找不到使用代理访问Internet的选项.我不仅仅为了旅游而需要它,而是为了总体上在Go中进行开发.
I want to run go install
to install the tour, but I can't find the option to use a proxy for internet access. I don't need this just for the tour but for developing in Go in general.
如何配置Go以使用代理.
How do I configure Go to use a proxy.
Go程序可以理解环境变量http_proxy
和no_proxy
,但这还不够,因为go get
使用源代码管理器来检索代码.因此,您还必须为SCM设置HTTP代理设置.将此用于Mercurial和
Go programs understand environment variables http_proxy
and no_proxy
, but that's not enough because go get
uses source control managers for retrieving code. So you have to set HTTP proxy settings for your SCM too. Use this for Mercurial and this for Git.
http_proxy
的值可以类似于http://user:password@host:port/
.用户,密码和端口部分是可选的. no_proxy
是不应该通过代理服务器连接的服务器的逗号分隔列表.其值可以类似于foo.com,bar.net:4000
.
http_proxy
value can be like http://user:password@host:port/
. User, password, and port parts are optional. no_proxy
is a comma-separated list of servers that should not be connected through proxy. Its value can be like foo.com,bar.net:4000
.
您可以在bash_profile
中设置这些环境变量,但是如果要将它们的使用范围限制为go
,则可以这样运行它:
You can set these environment variables in your bash_profile
, but if you want to limit their usage to go
, you can run it like this:
$ http_proxy=127.0.0.1:8080 go get code.google.com/p/go.crypto/bcrypt
如果这是您一直想要的,请设置此别名以避免每次都键入代理部分:
If that's what you always want, set this alias to avoid typing proxy part every time:
$ alias go='http_proxy=127.0.0.1:8080 go'
从现在开始,您可以正常使用go
,但是它使用您的HTTP代理.
From now on you can use go
normally, but it uses your HTTP proxy.