How do I configure go command to use a proxy?
Asked Answered
H

8

75

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.

Hyperbola answered 30/4, 2012 at 11:55 Comment(0)
R
144

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.

Reckon answered 30/4, 2012 at 14:46 Comment(10)
mercurial uses the http_proxy environment variable, too.Hyperbola
@Meow Best was is to use a tool like privoxy or torsocks to provide it as an HTTP proxy to the tools.Reckon
For https proxy, check here: #22060170Fabrication
For other proxy such as socks, I guess you can set it in IE options for Windows platform. But I didn't tested that.Fabrication
set http_proxy=127.0.0.1:8080 and set https_proxy=127.0.0.1:8080 if you are on Windows.Degraw
Sometimes for special character https://mcmap.net/q/218553/-how-can-i-set-a-proxy-server-for-gemBunche
plz do not forget https_proxy=Oarsman
seems only http_proxy not enough, https_proxy also need, @ ubuntu 20, go 1.14Kramlich
if you are using socks5 proxy on linux ubuntu , i had success with https_proxy=socks5://127.0.0.1:8080 go get ...Luncheon
if you are using go get, go mod tidy etc all requests goes through Go proxy GO_PROXY which by default is: proxy.golang.org, you can specify GO_NO_PROXY to go directly to specified url. HTTP_PROXY and NO_PROXY are two different variables and they are used in http transport.Danndanna
P
9

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

Puto answered 6/11, 2018 at 11:30 Comment(0)
C
8

This works for me:

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'

Note: for someones, protocol may be different https_proxy=http://127.0.0.1:1081

Communalize answered 23/5, 2018 at 14:0 Comment(1)
https_proxy works for my go installCastora
R
5

you can also map http requests to socks5 traffic by using https://github.com/cyfdecyf/cow/

very handy if you are blocked by GFW

Rickie answered 28/7, 2017 at 10:55 Comment(1)
It's better to add some detail that facilitates go get commandCommunalize
L
4

Add GOPROXY variable name and Variable value as your proxy in the System variable. This worked for me.

Leonardaleonardi answered 10/1, 2019 at 9:20 Comment(0)
B
3

You may want check 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)

If you already have shadowsocks listening on 1080, then you don't need provide any paramaters, just run graftcp-local, to proxy go get

$ ./graftcp go get -v golang.org/x/net/proxy
Brunobruns answered 25/8, 2018 at 4:53 Comment(0)
C
0
git config [--global] http.proxy http://proxy.example.com:port
git config [--global] https.proxy http://proxy.example.com:port

see https://github.com/golang/go/wiki/GoGetProxyConfig

Communalize answered 5/9, 2018 at 14:41 Comment(1)
I really wonder why - in my case go-dep - uses the git proxy value and not the env-variables - thank you for your commentMistake
P
0

I solved this problem with the Go command setting some variables in the Win10 system.

Here ("Using the cf CLI with a Proxy Server") you can find the information described below, with images. Also you can read information about:

  • Format of https_proxy
  • Use SOCKS5 with cf v3-ssh
  • Set https_proxy in Mac OS or Linux

I included in this answer only information about W10 because is the one I tested.

Windows 10

Set the new path variable.

  • From the search box, type in path
  • Select and open "Edit the system environment variables (control panel)".
  • "System properties" window will open.
  • Select "Advanced" tab.
  • Press "Environment Variables" button, a window with the same name will open.
  • In "System Variables" section, press the "New" button. "New System Variable" window will open.
  • You'll now add the needed variable, fill the fields as follows:
    • Variable name: https_proxy
    • Variable value:http://yourUserName:userNamePassword@yourIPaddress:port

Lastly...

I tested the installation command line for go.

Open the console, and type in: go install github.com/isacikgoz/gitbatch/cmd/gitbatch@latest

That's an example from this project: https://github.com/isacikgoz/gitbatch

This worked on my particular W10 19043 system.

Perron answered 10/8, 2021 at 12:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.