Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Merovius opened this issue Jan 12, 2021 · 2 comments
Open

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

Merovius opened this issue Jan 12, 2021 · 2 comments
Labels
Projects
Milestone

Comments

@Merovius
Copy link

@Merovius Merovius commented Jan 12, 2021

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.

@gopherbot gopherbot added this to the Proposal milestone Jan 12, 2021
@jayconrod
Copy link
Contributor

@jayconrod jayconrod commented Jan 12, 2021

cc @bcmills @matloob @rsc

Closely related: #32337

We've also talked about adding GOPROXY=cache, which would be similar to GOPROXY=file://$(go env GOMODCACHE)/cache/download, but would synthesize version lists and .info files.

@Merovius
Copy link
Author

@Merovius Merovius commented Jan 12, 2021

GOPROXY=cache would also address this and is, I think, a very logical place for that knob (and far easier to remember than the path).

@ianlancetaylor ianlancetaylor changed the title Proposal: cmd/go: Fallback to module cache, if proxy is not reachable proposal: cmd/go: fallback to module cache, if proxy is not reachable Jan 12, 2021
@ianlancetaylor ianlancetaylor added this to Incoming in Proposals Jan 12, 2021
@rsc rsc changed the title proposal: cmd/go: fallback to module cache, if proxy is not reachable proposal: cmd/go: add GOPROXY=cache to rely only on module cache Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Proposals
Incoming
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants