如何配置go命令以使用代理? [英] How do I configure go command to use a proxy?

查看:168
本文介绍了如何配置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_proxyno_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.

这篇关于如何配置go命令以使用代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆