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

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

问题描述

我想运行 go install 来安装 tour,但是我找不到使用代理访问 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 代理设置.将 this 用于 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天全站免登陆