Skip to content

golang: use pkg.go.dev v1beta API for package and version metadata#32

Merged
andrew merged 1 commit into
mainfrom
golang-pkgsite-api
May 22, 2026
Merged

golang: use pkg.go.dev v1beta API for package and version metadata#32
andrew merged 1 commit into
mainfrom
golang-pkgsite-api

Conversation

@andrew
Copy link
Copy Markdown
Contributor

@andrew andrew commented May 22, 2026

The Go team announced a JSON API for pkg.go.dev (https://go.dev/blog/pkgsite-api). This wires it into the golang client when running against the default proxy.

FetchPackage now calls /v1beta/module/{path}?licenses=true, which gives us the resolved repoUrl (so vanity imports like golang.org/x/sync get https://go.googlesource.com/sync instead of a guessed path that urlparser rejects), SPDX license types for Licenses, and the latest version for LatestVersion.

FetchVersions now calls /v1beta/versions/{path}, paginating over nextPageToken. Each item carries commitTime, retracted and deprecated, which replaces the N+1 .info requests against the proxy and lets us populate Version.Status for the first time.

Any pkgsite error, including 404, falls through to the existing goproxy protocol so a module that has just hit proxy.golang.org but not yet been indexed by pkg.go.dev still resolves. When baseURL is anything other than https://proxy.golang.org (private Athens, Artifactory, etc.) pkgsite is skipped entirely and behaviour is unchanged.

The API is v1beta; the path will change when it goes v1 but the blog post commits to backward compatibility from that point.

When using the default proxy, FetchPackage now hits /v1beta/module which
returns the resolved repository URL (correct for vanity imports), SPDX
license types, and the latest version. FetchVersions hits /v1beta/versions
which returns commit times and retracted/deprecated flags in a single
paginated response, replacing the N+1 .info calls against the proxy.

Any pkgsite failure (including 404, since pkg.go.dev can lag the proxy)
falls through to the existing goproxy protocol path. Custom proxies skip
pkgsite entirely.
@andrew andrew merged commit 0fd6b16 into main May 22, 2026
5 checks passed
@andrew andrew deleted the golang-pkgsite-api branch May 22, 2026 17:51
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