Documentation
¶
Overview ¶
Package registries provides clients for fetching package metadata from registry APIs.
The package supports multiple ecosystems (npm, PyPI, Cargo, RubyGems, Go modules) with a unified interface for fetching package information, versions, dependencies, and maintainers.
Basic usage:
import (
"context"
"github.com/git-pkgs/registries"
_ "github.com/git-pkgs/registries/internal/cargo"
)
client := registries.DefaultClient()
reg, err := registries.New("cargo", "", client)
if err != nil {
log.Fatal(err)
}
pkg, err := reg.FetchPackage(context.Background(), "serde")
if err != nil {
log.Fatal(err)
}
fmt.Println(pkg.Name, pkg.Repository)
To automatically import all supported ecosystems, use the imports subpackage:
import ( "github.com/git-pkgs/registries" _ "github.com/git-pkgs/registries/all" )
Index ¶
- Constants
- Variables
- func BuildURLs(urls URLBuilder, name, version string) map[string]string
- func BulkFetchLatestVersions(ctx context.Context, purls []string, c *Client) map[string]*Version
- func BulkFetchLatestVersionsWithConcurrency(ctx context.Context, purls []string, c *Client, concurrency int) map[string]*Version
- func BulkFetchPackages(ctx context.Context, purls []string, c *Client) map[string]*Package
- func BulkFetchPackagesWithConcurrency(ctx context.Context, purls []string, c *Client, concurrency int) map[string]*Package
- func BulkFetchVersions(ctx context.Context, purls []string, c *Client) map[string]*Version
- func BulkFetchVersionsWithConcurrency(ctx context.Context, purls []string, c *Client, concurrency int) map[string]*Version
- func DefaultURL(ecosystem string) string
- func NPMProvenance(v *Version) (*NPMAttestationRef, []NPMSignature)
- func SupportedEcosystems() []string
- type Artifact
- type Client
- type Dependency
- type HTTPError
- type Maintainer
- type NPMAttestationRef
- type NPMSignature
- type NotFoundError
- type Option
- type PURL
- type Package
- type RateLimitError
- type RateLimiter
- type Registry
- type Scope
- type URLBuilder
- type Version
- func FetchLatestVersion(ctx context.Context, reg Registry, name string) (*Version, error)
- func FetchLatestVersionFromPURL(ctx context.Context, purl string, c *Client) (*Version, error)
- func FetchVersionFromPURL(ctx context.Context, purl string, c *Client) (*Version, error)
- func SelectLatestVersion(versions []Version, ecosystem, advertised string) *Version
- type VersionStatus
Constants ¶
const ( Runtime = core.Runtime Development = core.Development Test = core.Test Build = core.Build Optional = core.Optional StatusNone = core.StatusNone StatusYanked = core.StatusYanked StatusDeprecated = core.StatusDeprecated StatusRetracted = core.StatusRetracted )
Re-export constants
Variables ¶
var ( ErrNotFound = client.ErrNotFound // ErrResponseTooLarge is returned when a response body exceeds the client limit. ErrResponseTooLarge = client.ErrResponseTooLarge )
Re-export errors
var WithHTTPClient = client.WithHTTPClient
WithHTTPClient swaps in a caller-supplied HTTP client.
var WithMaxResponseSize = client.WithMaxResponseSize
WithMaxResponseSize sets the limit for buffered response bodies.
var WithMaxRetries = client.WithMaxRetries
WithMaxRetries sets the maximum number of retries.
var WithMaxStreamSize = client.WithMaxStreamSize
WithMaxStreamSize sets the limit for streamed response bodies.
var WithSafeHTTP = client.WithSafeHTTP
WithSafeHTTP applies protections for requests to untrusted hosts.
var WithTimeout = client.WithTimeout
WithTimeout sets the HTTP client timeout.
var WithTransport = client.WithTransport
WithTransport replaces the underlying HTTP transport.
Functions ¶
func BuildURLs ¶
func BuildURLs(urls URLBuilder, name, version string) map[string]string
BuildURLs returns a map of all non-empty URLs for a package. Keys are "registry", "download", "docs", and "purl".
func BulkFetchLatestVersions ¶
BulkFetchLatestVersions fetches the latest version for multiple PURLs in parallel using the shared latest-release policy.
func BulkFetchLatestVersionsWithConcurrency ¶
func BulkFetchLatestVersionsWithConcurrency(ctx context.Context, purls []string, c *Client, concurrency int) map[string]*Version
BulkFetchLatestVersionsWithConcurrency fetches latest versions with a custom concurrency limit.
func BulkFetchPackages ¶
BulkFetchPackages fetches package metadata for multiple PURLs in parallel. Individual fetch errors are silently ignored - those PURLs are omitted from results. Returns a map of PURL to Package.
func BulkFetchPackagesWithConcurrency ¶
func BulkFetchPackagesWithConcurrency(ctx context.Context, purls []string, c *Client, concurrency int) map[string]*Package
BulkFetchPackagesWithConcurrency fetches packages with a custom concurrency limit.
func BulkFetchVersions ¶
BulkFetchVersions fetches version metadata for multiple versioned PURLs in parallel. PURLs without versions are silently skipped. Individual fetch errors are silently ignored - those PURLs are omitted from results. Returns a map of PURL to Version.
func BulkFetchVersionsWithConcurrency ¶
func BulkFetchVersionsWithConcurrency(ctx context.Context, purls []string, c *Client, concurrency int) map[string]*Version
BulkFetchVersionsWithConcurrency fetches versions with a custom concurrency limit.
func DefaultURL ¶
DefaultURL returns the default registry URL for an ecosystem.
func NPMProvenance ¶
func NPMProvenance(v *Version) (*NPMAttestationRef, []NPMSignature)
NPMProvenance reads the npm-specific provenance fields from a Version returned by FetchVersionFromPURL or FetchVersions. Returns (nil, nil) when no provenance metadata is recorded — the registry doesn't always publish either field. The signatures slice may be empty even when the attestation pointer is set, and vice versa.
func SupportedEcosystems ¶
func SupportedEcosystems() []string
SupportedEcosystems returns all registered ecosystem types. Note: ecosystems must be imported to be registered.
Types ¶
type Client ¶
Client is an HTTP client with retry logic for registry APIs.
func DefaultClient ¶
func DefaultClient() *Client
DefaultClient returns a client with sensible defaults: - 30s timeout - 5 retries with exponential backoff - Retry on 429 and 5xx responses
type Dependency ¶
type Dependency = core.Dependency
Dependency represents a package dependency.
func FetchDependenciesFromPURL ¶
FetchDependenciesFromPURL fetches dependencies for a specific version using a PURL. Returns an error if the PURL doesn't include a version.
type Maintainer ¶
type Maintainer = core.Maintainer
Maintainer represents a package maintainer.
func FetchMaintainersFromPURL ¶
FetchMaintainersFromPURL fetches maintainer information using a PURL.
type NPMAttestationRef ¶
type NPMAttestationRef = npm.AttestationRef
NPMAttestationRef mirrors npm's dist.attestations pointer published alongside a version when the publisher used trusted publishing.
type NPMSignature ¶
NPMSignature mirrors one entry from a version's dist.signatures array — an ECDSA P-256 signature over the integrity string with keyid identifying the verifying key in /-/npm/v1/keys.
type Registry ¶
Registry is the interface implemented by all ecosystem registry clients.
type Version ¶
Version represents a specific version of a package.
func FetchLatestVersion ¶
FetchLatestVersion returns the registry-advertised latest version when available. Otherwise it selects the latest active version by publication time, falling back to ecosystem version ordering when timestamps are absent. It returns nil when the registry reports no active versions. If fetching versions fails after an advertised version is found, it returns that version without metadata and suppresses the versions error.
func FetchLatestVersionFromPURL ¶
FetchLatestVersionFromPURL returns the latest version for a PURL using the shared latest-release policy.
func FetchVersionFromPURL ¶
FetchVersionFromPURL fetches a specific version's metadata using a PURL. Returns an error if the PURL doesn't include a version.
func SelectLatestVersion ¶
SelectLatestVersion applies the shared latest-release policy to versions. An advertised version takes precedence regardless of status; otherwise see FetchLatestVersion for the selection order. The input slice is not modified.
type VersionStatus ¶
type VersionStatus = core.VersionStatus
VersionStatus represents the status of a package version.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package all imports all supported registry implementations.
|
Package all imports all supported registry implementations. |
|
Package changes reads the feeds in which registries list the packages that changed since a given point, so a cache or mirror can refresh just those.
|
Package changes reads the feeds in which registries list the packages that changed since a given point, so a cache or mirror can refresh just those. |
|
Package client provides an HTTP client with retry logic for registry APIs.
|
Package client provides an HTTP client with retry logic for registry APIs. |
|
Package fetch provides streaming artifact downloading with retry, circuit breaking, and URL resolution for package registries.
|
Package fetch provides streaming artifact downloading with retry, circuit breaking, and URL resolution for package registries. |
|
internal
|
|
|
apk
Package apk provides a registry client for Alpine APK repositories.
|
Package apk provides a registry client for Alpine APK repositories. |
|
cargo
Package cargo provides a registry client for crates.io.
|
Package cargo provides a registry client for crates.io. |
|
clojars
Package clojars provides a registry client for clojars.org (Clojure).
|
Package clojars provides a registry client for clojars.org (Clojure). |
|
cocoapods
Package cocoapods provides a registry client for CocoaPods (iOS/macOS).
|
Package cocoapods provides a registry client for CocoaPods (iOS/macOS). |
|
conda
Package conda provides a registry client for Anaconda/Conda packages.
|
Package conda provides a registry client for Anaconda/Conda packages. |
|
core
Package core provides shared types and the registry system.
|
Package core provides shared types and the registry system. |
|
cpan
Package cpan provides a registry client for CPAN/MetaCPAN (Perl).
|
Package cpan provides a registry client for CPAN/MetaCPAN (Perl). |
|
cran
Package cran provides a registry client for CRAN (R packages).
|
Package cran provides a registry client for CRAN (R packages). |
|
deno
Package deno provides a registry client for Deno modules.
|
Package deno provides a registry client for Deno modules. |
|
dub
Package dub provides a registry client for D language packages.
|
Package dub provides a registry client for D language packages. |
|
elm
Package elm provides a registry client for Elm packages.
|
Package elm provides a registry client for Elm packages. |
|
githubactions
Package githubactions provides a registry client for GitHub Actions.
|
Package githubactions provides a registry client for GitHub Actions. |
|
golang
Package golang provides a registry client for the Go module proxy.
|
Package golang provides a registry client for the Go module proxy. |
|
hackage
Package hackage provides a registry client for Hackage (Haskell).
|
Package hackage provides a registry client for Hackage (Haskell). |
|
haxelib
Package haxelib provides a registry client for Haxe packages.
|
Package haxelib provides a registry client for Haxe packages. |
|
helm
Package helm provides a registry client for Helm HTTP repositories.
|
Package helm provides a registry client for Helm HTTP repositories. |
|
hex
Package hex provides a registry client for hex.pm (Elixir/Erlang).
|
Package hex provides a registry client for hex.pm (Elixir/Erlang). |
|
homebrew
Package homebrew provides a registry client for Homebrew packages.
|
Package homebrew provides a registry client for Homebrew packages. |
|
julia
Package julia provides a registry client for Julia packages.
|
Package julia provides a registry client for Julia packages. |
|
luarocks
Package luarocks provides a registry client for Lua packages.
|
Package luarocks provides a registry client for Lua packages. |
|
maven
Package maven provides a registry client for Maven Central (Java).
|
Package maven provides a registry client for Maven Central (Java). |
|
nimble
Package nimble provides a registry client for Nim packages.
|
Package nimble provides a registry client for Nim packages. |
|
npm
Package npm provides a registry client for npmjs.com.
|
Package npm provides a registry client for npmjs.com. |
|
nuget
Package nuget provides a registry client for nuget.org (.NET).
|
Package nuget provides a registry client for nuget.org (.NET). |
|
packagist
Package packagist provides a registry client for packagist.org (PHP/Composer).
|
Package packagist provides a registry client for packagist.org (PHP/Composer). |
|
pub
Package pub provides a registry client for pub.dev (Dart/Flutter).
|
Package pub provides a registry client for pub.dev (Dart/Flutter). |
|
pypi
Package pypi provides a registry client for pypi.org.
|
Package pypi provides a registry client for pypi.org. |
|
rubygems
Package rubygems provides a registry client for rubygems.org.
|
Package rubygems provides a registry client for rubygems.org. |
|
swift
Package swift implements the Swift package registry protocol.
|
Package swift implements the Swift package registry protocol. |
|
terraform
Package terraform provides a registry client for Terraform modules and providers.
|
Package terraform provides a registry client for Terraform modules and providers. |
|
urlparser
Package urlparser extracts repository paths from git URLs.
|
Package urlparser extracts repository paths from git URLs. |
|
Package safehttp builds an http.Client suitable for fetching from untrusted hosts.
|
Package safehttp builds an http.Client suitable for fetching from untrusted hosts. |