feat: add Go modules registry support#42
Open
mvanhorn wants to merge 2 commits intovercel-labs:mainfrom
Open
Conversation
Add go: and golang: prefixes to fetch Go module source code via proxy.golang.org. Follows the existing registry pattern used by npm, PyPI, and crates.io modules. Usage: opensrc path go:golang.org/x/tools opensrc path golang:github.com/gin-gonic/gin opensrc path go:golang.org/x/tools@v0.43.0 The Go module proxy returns the canonical git repository URL in its Origin field. For modules without Origin data, the URL is derived from the module path. Also adds --go flag to the clean command and Go modules to list output.
Go standard library extension modules (golang.org/x/*) resolve to go.googlesource.com which uses a flat host/repo URL structure. The cache system expects host/owner/repo, so these are rewritten to their official GitHub mirrors at github.com/golang/*.
|
@mvanhorn is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
| fn module_url(module: &str, version: Option<&str>) -> String { | ||
| let encoded = module.to_lowercase(); | ||
| match version { | ||
| Some(v) => format!("{GO_PROXY}/{encoded}/@v/{v}.info"), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
go:andgolang:prefixes to fetch Go module source code via proxy.golang.org. Follows the existing registry pattern used by npm, PyPI, and crates.io.Usage
Also adds
--goflag toopensrc cleanand shows Go modules inopensrc list.Demo
How it works
The Go module proxy at proxy.golang.org returns a JSON response with the canonical git repository URL in its
Origin.URLfield. For golang.org/x/* modules hosted on go.googlesource.com, the URL is rewritten to the official GitHub mirror at github.com/golang/* (the cache system expects host/owner/repo structure).For modules without
Origindata (older versions), the git URL is derived from the module path.Changes
go.rs- New registry module:parse_go_specandresolve_go_modulefollowing the existing patternmod.rs- AddGovariant toRegistryenum,go:andgolang:prefixes, extendparse_package_specandresolve_packagemain.rs- Add--goflag to clean commandlist.rs- Add Go modules to the registries display and empty-state help textTesting
8 new unit tests covering spec parsing, googlesource URL normalization, and module path resolution. All 40 tests pass (38 existing + 2 new googlesource tests + 6 existing Go tests = 40 with
--test-threads=1).This contribution was developed with AI assistance (Claude Code).