cratesio

package
v0.2.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: 12 Imported by: 0

Documentation

Overview

Package cratesio is the library behind the cratesio command line: the HTTP client, request shaping, and the typed data models for crates.io.

The crates.io v1 API is public and requires no authentication, but every request MUST carry a descriptive User-Agent or the server returns 403. Set it via Config.UserAgent or DefaultConfig(), which fills it in.

Index

Constants

View Source
const Host = "crates.io"

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

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when the API returns a 404 or an empty result.

Functions

This section is empty.

Types

type Category

type Category struct {
	ID          string `kit:"id" json:"id"`
	Name        string `json:"category"`
	CratesCount int    `json:"crates_cnt"`
	Description string `json:"description"`
}

Category is a record for a crates.io category.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the crates.io v1 API.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured from cfg.

func (*Client) GetCrate added in v0.2.0

func (c *Client) GetCrate(ctx context.Context, name string) (*Crate, error)

GetCrate fetches metadata for a single crate by name.

func (*Client) ListCategories added in v0.2.0

func (c *Client) ListCategories(ctx context.Context, limit int) ([]Category, error)

ListCategories lists crates.io categories, limited to limit results.

func (*Client) ListVersions added in v0.2.0

func (c *Client) ListVersions(ctx context.Context, name string, limit int) ([]Version, error)

ListVersions lists all published versions of a crate, truncated to limit.

func (*Client) SearchCrates added in v0.2.0

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

SearchCrates searches crates.io for crates matching query. limit controls the max results; capped at 100 per API page.

type Config

type Config struct {
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
	BaseURL   string // override for tests
}

Config holds all tunable parameters for a Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults. UserAgent is required by crates.io; the default identifies this client.

type Crate

type Crate struct {
	ID              string `kit:"id" json:"id"`
	Name            string `json:"name"`
	Description     string `json:"description"`
	Downloads       int64  `json:"downloads"`
	RecentDownloads int64  `json:"recent_downloads"`
	MaxVersion      string `json:"max_version"`
	NewestVersion   string `json:"newest_version"`
	Homepage        string `json:"homepage"`
	Repository      string `json:"repository"`
}

Crate is the primary record for a crates.io package.

type Domain added in v0.2.0

type Domain struct{}

Domain is the crates.io driver.

func (Domain) Classify added in v0.2.0

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

Classify turns any accepted input into the canonical (type, id), so `ant resolve` and `ant url` touch no network. A crate name goes to ("crate", name); anything else (a search query with spaces, uppercase letters) goes to ("query", input).

func (Domain) Info added in v0.2.0

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 added in v0.2.0

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

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

func (Domain) Register added in v0.2.0

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

Register installs the client factory and every operation onto app.

type Version

type Version struct {
	ID        int    `kit:"id" json:"id"`
	CrateName string `json:"crate"`
	Num       string `json:"num"`
	Downloads int64  `json:"downloads"`
	Yanked    bool   `json:"yanked"`
	License   string `json:"license"`
	CreatedAt string `json:"created_at"`
}

Version is a record for a single published version of a crate.

Jump to

Keyboard shortcuts

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