Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure go command to use a proxy?

Tags:

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.

How do I configure Go to use a proxy.

like image 358
oers Avatar asked Apr 30 '12 11:04

oers


People also ask

How do I run a proxy command?

Click Start, click Run, type cmd, and then click OK. At the command prompt, type netsh winhttp set proxy proxyservername:portnumber, and then press ENTER. In this command, replace proxyservername with the fully qualified domain name of the proxy server.


2 Answers

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 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.

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' 

From now on you can use go normally, but it uses your HTTP proxy.

like image 198
Mostafa Avatar answered Oct 22 '22 22:10

Mostafa


On Windows command line:

set http_proxy=http://[user]:[pass]@[proxy_ip]:[proxy_port]/ set https_proxy=http://[user]:[pass]@[proxy_ip]:[proxy_port]/

...then navigate to https://github.com/ and download the GitHub certificate (I set the name as goland_cert.cer)

...now execute the OpenSSL command to export this to PEM format

openssl x509 -inform der -in goland_cert.cer -out goland_cert.pem

...finally set the certificate in git global config

git config --global http.sslCAInfo C:/Users/[User]/certs/golang_cert.pem

like image 28
Marco Avatar answered Oct 23 '22 00:10

Marco