4

I'm trying to get Go to use an internal enterprise Go-Proxy for module download - which requires an http_proxy to be accessible (enterprise firewall). However go get -u golang.org/x/lint/golint fails:

package golang.org/x/lint/golint: unrecognized import path "golang.org/x/lint/golint": https fetch: Get "https://golang.org/x/lint/golint?go-get=1": Forbidden

My setup:

  • http_proxy and https_proxy environment variables are set
  • no_proxy does not contain the IP or hostname of my Go-Proxy
  • GOPROXY is set (go env -w GOPROXY=https://artifactory.mycompany.com/api/go/myrepo-go-virtual)

I checked:

  • Using curl and directly querying the GOPROXY server works fine and I can download the file (so the https_proxy setting works)
  • Counter-check with curl and explicitly unsetting http/https_proxy: No connection, as expected

Using tcpdump, I discovered that running go get seems to ignore my GOPROXY and ask my http_proxy to connect directly to the original url on golang.org (Options/sequence and ack numbers omitted for brevity), which the proxy/firewall blocks.

06:52:53.926397 IP <my_ip.port> > <proxy.port>: Flags [S], length 0
06:52:53.927206 IP <proxy.port> > <my_ip.port>: Flags [S.], length 0
06:52:53.927232 IP <my_ip.port> > <proxy.port>: Flags [.], length 0
06:52:53.932003 IP <my_ip.port> > <proxy.port>: Flags [P.], length 89: HTTP: CONNECT golang.org:443 HTTP/1.1
06:52:53.932638 IP <proxy.port> > <my_ip.port>: Flags [.], length 0
06:52:53.933100 IP <proxy.port> > <my_ip.port>: Flags [P.], length 3939: HTTP: HTTP/1.1 403 Forbidden

Question: Why does Go ignore the GOPROXY? Did I not set something up correctly?

I'm using Go 1.15.3 in the golang:1.15.3 Docker container (with some added tools to check connectivity)

Patrick
  • 4,720
  • 4
  • 41
  • 71
  • Does `go env` display the `GOPROXY` variable set to a value you expect it to be set to? – kostix Oct 21 '20 at 07:41
  • @kostix Yes, it does. Both when I use `go env -w GOPROXY=...` to set it, and when I just use `export GOPROXY=...` – Patrick Oct 21 '20 at 07:42
  • Do you have `GONOPROXY` set by chance (see [this](https://github.com/golang/go/issues/39835#issuecomment-649827269))? – kostix Oct 21 '20 at 07:46
  • I don't think so: go env shows it to be empty (`GONOPROXY=""`) – Patrick Oct 21 '20 at 07:56

1 Answers1

2

Try this: set GO111MODULE=on to use GOPROXY Or run go mod init before you run go get

ws_
  • 1,076
  • 9
  • 18
  • `GO111MODULE=on` did the trick. Thank you - this was driving me insane. – Patrick Oct 21 '20 at 08:43
  • 1
    see this page if you want to go deeper : – ws_ Oct 21 '20 at 09:00
  • 1
    @ws_, why one would need to set this with Go 1.15.3? Do you mean the (weird) superposition of these two facts: 1) the OP has his project checked out under GOPATH and 2) when working under GOPATH the `GOPROXY` is not considered as `go` is working in non-module, legacy, mode? – kostix Oct 22 '20 at 09:01
  • @kostix Your describtions are correct. In go proxy provider's site,usually they would provide this instruction like `goproxy.io`. The better way is to run `go mod init` before `go get` to use `GOPROXY` and forget about `GO111MODULE` . – ws_ Oct 23 '20 at 02:41