mavencentral

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package mavencentral is the library behind the mavencentral command line: the HTTP client, request shaping, and the typed data models for Maven Central.

The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public site throws under load.

Index

Constants

View Source
const BaseURL = "https://search.maven.org/solrsearch"

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "mavencentral-cli/dev (+https://github.com/tamnd/mavencentral-cli)"

DefaultUserAgent identifies the client to Maven Central. A real, honest User-Agent is both polite and the thing most likely to keep you unblocked.

View Source
const Host = "search.maven.org"

Host is the site this client talks to, and the host the URI driver in domain.go claims.

Variables

This section is empty.

Functions

This section is empty.

Types

type Artifact

type Artifact struct {
	ID            string   `kit:"id" json:"id"`
	GroupID       string   `json:"group_id"`
	ArtifactID    string   `json:"artifact_id"`
	LatestVersion string   `json:"latest_version"`
	Packaging     string   `json:"packaging"`
	VersionCount  int      `json:"version_count"`
	UpdatedAt     int64    `json:"updated_at_ms"`
	Extensions    []string `json:"extensions"`
}

Artifact is one Maven artifact, as returned by a default-mode search (latest version per artifact).

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	BaseURL   string
	// Rate is the minimum gap between requests. Zero means no pacing.
	Rate    time.Duration
	Retries int
	// contains filtered or unexported fields
}

Client talks to Maven Central over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults.

func NewClientFromConfig

func NewClientFromConfig(cfg Config) *Client

NewClientFromConfig returns a Client configured from cfg.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) ([]byte, error)

Get fetches url and returns the response body. It paces and retries according to the client's settings. The caller owns nothing extra; the body is read fully and closed here.

func (*Client) GetVersions

func (c *Client) GetVersions(ctx context.Context, groupID, artifactID string, limit int) ([]Version, error)

GetVersions lists all known versions of a specific artifact identified by groupID and artifactID. It returns up to limit results.

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string, limit int) ([]Artifact, error)

Search searches Maven Central for artifacts matching query. It returns up to limit results, each showing the latest version of a matching artifact.

type Config

type Config struct {
	BaseURL string
	Rate    time.Duration
	Retries int
	Timeout time.Duration
}

Config holds the tunable settings for the client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Domain

type Domain struct{}

Domain is the Maven Central driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (type, id). A "group:artifact:version" or "group:artifact" pattern (contains ":") is an artifact; anything else is treated as a query string.

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate is the inverse: the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Version

type Version struct {
	ID         string `kit:"id" json:"id"`
	GroupID    string `json:"group_id"`
	ArtifactID string `json:"artifact_id"`
	Version    string `json:"version"`
	Packaging  string `json:"packaging"`
	UpdatedAt  int64  `json:"updated_at_ms"`
}

Version is one released version of a specific Maven artifact, as returned by a core=gav search.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL