我想运行go install
以安装tour,但找不到使用代理访问 Internet 的选项。我不只是为了巡回演出而需要这个,而是为了在 Go 中进行开发。
如何配置 Go 以使用代理。
Go 程序理解环境变量http_proxy
和no_proxy
,但这还不够,因为go get
使用源代码控制管理器来检索代码。所以你也必须为你的 SCM 设置 HTTP 代理设置。将其用于 Mercurial,将其用于 Git。
http_proxy
值可以像http://user:password@host:port/
。用户、密码和端口部分是可选的。no_proxy
是不应通过代理连接的服务器的逗号分隔列表。它的价值可以像foo.com,bar.net:4000
。
你可以在你的 中设置这些环境变量bash_profile
,但是如果你想限制它们的使用go
,你可以像这样运行它:
$ http_proxy=127.0.0.1:8080 go get code.google.com/p/go.crypto/bcrypt
如果这是您一直想要的,请设置此别名以避免每次都输入代理部分:
$ alias go='http_proxy=127.0.0.1:8080 go'
从现在开始您可以go
正常使用,但它使用您的 HTTP 代理。
在 Windows 命令行上:
set http_proxy=http://[user]:[pass]@[proxy_ip]:[proxy_port]/
set https_proxy=http://[user]:[pass]@[proxy_ip]:[proxy_port]/
...然后导航到https://github.com/并下载 GitHub 证书(我将名称设置为goland_cert.cer
)
...现在执行 OpenSSL 命令将其导出为 PEM 格式
openssl x509 -inform der -in goland_cert.cer -out goland_cert.pem
...最后在 git global config 中设置证书
git config --global http.sslCAInfo C:/Users/[User]/certs/golang_cert.pem
您还可以使用https://github.com/cyfdecyf/cow/将 http 请求映射到 socks5 流量
如果你被 GFW 屏蔽了,非常方便
这对我有用:
alias go='http_proxy=http://127.0.0.1:1081/ https_proxy=http://127.0.0.1:1081/ no_proxy=localhost,127.0.0.0/8,::1 go'
注意:对于某些人,协议可能会有所不同https_proxy=http://127.0.0.1:1081
您可能需要检查 https://github.com/hmgle/graftcp,
$ graftcp-local/graftcp-local -h
Usage of graftcp-local/graftcp-local:
-config string
Path to the configuration file
-listen string
Listen address (default ":2233")
-logfile string
Write logs to file
-loglevel value
Log level (0-6) (default 1)
-pipepath string
Pipe path for graftcp to send address info (default "/tmp/graftcplocal.fifo")
-service string
Control the system service: ["start" "stop" "restart" "install" "uninstall"]
-socks5 string
SOCKS5 address (default "127.0.0.1:1080")
-syslog
Send logs to the local system logger (Eventlog on Windows, syslog on Unix)
如果您已经在 1080 上监听了 shadowsocks,那么您不需要提供任何参数,只需运行graftcp-local
即可代理 go get
$ ./graftcp go get -v golang.org/x/net/proxy
在系统变量中添加GOPROXY
变量名称和变量值。your proxy
这对我有用。
我通过在 Win10 系统中设置一些变量的 Go 命令解决了这个问题。
在这里(“将 cf CLI 与代理服务器一起使用”)您可以找到下面描述的信息以及图像。您还可以阅读以下信息:
我在此答案中仅包含有关 W10 的信息,因为它是我测试过的。
设置新的路径变量。
path
https_proxy
http://yourUserName:userNamePassword@yourIPaddress:port
我测试了 go 的安装命令行。
打开控制台,输入:go install github.com/isacikgoz/gitbatch/cmd/gitbatch@latest
这是这个项目的一个例子:https ://github.com/isacikgoz/gitbatch
这适用于我的特定 W10 19043 系统。
git config [--global] http.proxy http://proxy.example.com:port
git config [--global] https.proxy http://proxy.example.com:port
见https://github.com/golang/go/wiki/GoGetProxyConfig
注意: 此答案已收到正面和负面反馈,如果此方法对您的情况没有帮助,请在单击否决之前留下一些评论,因为这实际上已记录在案并且在我的案例中有效。我们最好知道为什么它对您不起作用。谢谢。