How do I configure go command to use a proxy?

后端 未结 7 1675
鱼传尺愫
鱼传尺愫 2020-12-02 05:34

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 deve

相关标签:
7条回答
  • 2020-12-02 05:34
    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

    Note: This answer has received both positive and negative feedback, if this method does not help on your case, please leave some comments before you click down-vote, cause this is actually documented and is working in my case. We'd better know why it does not work for you. Thanks.

    0 讨论(0)
  • 2020-12-02 05:35

    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.

    0 讨论(0)
  • 2020-12-02 05:39

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

    very handy if you are blocked by GFW

    0 讨论(0)
  • 2020-12-02 05:47

    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

    0 讨论(0)
  • 2020-12-02 05:50

    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
    
    0 讨论(0)
  • 2020-12-02 05:58

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

    0 讨论(0)
提交回复
热议问题