我如何配置Go使用代理? [英] How do I configure Go to use a proxy?

查看:219
本文介绍了我如何配置Go使用代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行 go install 来安装旅游,但我无法找到使用代理访问互联网的选项。我不需要这个只是为了巡演,而是为了在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 code>使用源代码控制管理器来检索代码。所以你必须为你的SCM设置HTTP代理设置。使用用于Mercurial和为Git。

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天全站免登陆