Skip to content

feat: add Go modules registry support#42

Open
mvanhorn wants to merge 2 commits intovercel-labs:mainfrom
mvanhorn:feat/go-modules-registry
Open

feat: add Go modules registry support#42
mvanhorn wants to merge 2 commits intovercel-labs:mainfrom
mvanhorn:feat/go-modules-registry

Conversation

@mvanhorn
Copy link
Copy Markdown

@mvanhorn mvanhorn commented Apr 9, 2026

Summary

Adds 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.

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

Also adds --go flag to opensrc clean and shows Go modules in opensrc list.

Demo

Go modules 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.URL field. 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 Origin data (older versions), the git URL is derived from the module path.

Changes

  • go.rs - New registry module: parse_go_spec and resolve_go_module following the existing pattern
  • mod.rs - Add Go variant to Registry enum, go: and golang: prefixes, extend parse_package_spec and resolve_package
  • main.rs - Add --go flag to clean command
  • list.rs - Add Go modules to the registries display and empty-state help text

Testing

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).

cargo test --manifest-path packages/opensrc/cli/Cargo.toml -- --test-threads=1
cargo clippy --manifest-path packages/opensrc/cli/Cargo.toml -- -D warnings
cargo fmt --manifest-path packages/opensrc/cli/Cargo.toml --check

This contribution was developed with AI assistance (Claude Code).

mvanhorn added 2 commits April 9, 2026 07:16
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/*.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 9, 2026

@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"),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go module proxy URL encoding uses .to_lowercase() instead of proper case encoding, causing incorrect repository URLs for modules with uppercase letters in their paths.

Fix on Vercel

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant