Skip to content

Conversation

@mxr
Copy link
Member

@mxr mxr commented Jan 15, 2026

I'm trying to set up a mirror for mvdan.cc/sh/v3/cmd/shfmt/ but the actual module is mvdan.cc/sh/v3 (there are a couple tools in the module). go install itself ultimately resolves this by trying to take the longest path and truncating until the module is found:

For example, suppose the go command is looking for a module that provides the package golang.org/x/net/html, and GOPROXY is set to https://corp.example.com,https://proxy.golang.org. The go command may make the following requests:

To https://corp.example.com/ (in parallel):
Request for latest version of golang.org/x/net/html
Request for latest version of golang.org/x/net
Request for latest version of golang.org/x
Request for latest version of golang.org

https://go.dev/ref/mod#resolve-pkg-mod

(I am not implementing the entirety of Go module resolution here, just taking the longest non-404 path, since I imagine this approach works for most cases.)

Tested the change locally by creating a mirror with pre-commit-mirror . --language=golang --package-name=mvdan.cc/sh/v3/cmd/shfmt --types=shell --entry=shfmt --args='-w', then I ran it on a shell file and confirmed the file was formatted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants