Skip to content

proposal: cmd/go: add GOPROXY=cache to rely only on module cache #43646

Open
@Merovius

Description

@Merovius

When I try to import a yet-unrequired module, e.g.

mero@hix ~/src/github.com/Merovius/foo$ cat foo.go 
package main

import "rsc.io/qr"

func main() {
	var _ qr.Code
}
mero@hix ~/src/github.com/Merovius/foo$ cat go.mod
module github.com/Merovius/foo

go 1.15

and I run go mod tidy, while not connected to the internet, I get an error

go: finding module for package rsc.io/qr
github.com/Merovius/foo imports
	rsc.io/qr: module rsc.io/qr: Get "https://proxy.golang.org/rsc.io/qr/@v/list": dial tcp: lookup proxy.golang.org on [::1]:53: read udp [::1]:57927->[::1]:53: read: connection refused

That makes sense - the proxy is not reachable. However, my module cache contains a usable version of this module:

mero@hix ~/src/github.com/Merovius/foo$ l -d ~/pkg/mod/rsc.io/qr@v0.2.0 
dr-x------. 5 mero mero 4,0K 14. Mai 2020  /home/mero/pkg/mod/rsc.io/qr@v0.2.0

So, it might be a reasonable course of action for me, to just use the version I have in the cache - whether it is the latest, or not. If I want to do that, as far as I can tell, either

a) I have to look up what versions I have in my cache and run go get rsc.io/qr@v0.2.0, to update go.mod. It would be great, if that could be automated, or
b) set GOPROXY=file:///home/mero/pkg/mod/cache/download and run go mod tidy

Both of these can be considered somewhat clunky (and the latter is not very discoverable). I would like to suggest to make this easier. There are several ways this could happen:

  1. Automatically fall back to the module cache when running go mod tidy or similar and a network error happens. IMO that would be the most convenient - it also has the downside of unexpectedly adding an outdated version of the module.
  2. Add a value to the -mod flag that is equivalent to -mod=mod, but only touching the local cache.
  3. Add a flag to go mod tidy (and similar), to use the local cache as a proxy (essentially automate setting the environment variable).

It's also fine, if this is deemed WAI, of course. I just thought I would suggest it after the case came up on golang-nuts.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions