cratesio

package
v0.1.2 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 cratesio is the library behind the crates command: 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 it does require a descriptive User-Agent header or it returns 403.

Index

Constants

View Source
const DefaultUserAgent = "cratesio-cli/0.1.0 (github.com/tamnd/cratesio-cli)"

DefaultUserAgent is the User-Agent sent on every request. crates.io returns 403 if this header is absent or generic.

Variables

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

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

Functions

This section is empty.

Types

type Category

type Category struct {
	Slug        string `json:"slug"`
	Name        string `json:"category"`
	Description string `json:"description"`
	CratesCount int    `json:"crates_cnt"`
}

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

func (c *Client) Categories(ctx context.Context) ([]Category, error)

Categories lists all crates.io categories.

func (*Client) Crate

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

Crate fetches metadata for a single crate by name.

func (*Client) Deps

func (c *Client) Deps(ctx context.Context, name string) ([]Dep, error)

Deps returns the dependencies of a crate's latest version. It first resolves the max_version via a Crate call, then fetches dependencies.

func (*Client) Keywords

func (c *Client) Keywords(ctx context.Context) ([]Keyword, error)

Keywords lists popular keywords on crates.io.

func (*Client) Owners

func (c *Client) Owners(ctx context.Context, name string) ([]Owner, error)

Owners lists the owners of a crate (users and teams).

func (*Client) ReverseDeps added in v0.1.2

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

ReverseDeps returns crates that depend on the given crate (reverse dependencies). limit controls the max results; 0 uses the API default (100).

func (*Client) Search

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

Search searches crates.io for crates matching query. sort is one of: downloads, alpha, new_crates, new_versions, recent_downloads. limit controls the max results returned.

func (*Client) Top

func (c *Client) Top(ctx context.Context, page, limit int) ([]Crate, error)

Top returns the most downloaded crates on the given page (1-based). limit clips the returned slice.

func (*Client) Versions

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

Versions lists all published versions of a crate (newest first).

type Config

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

Config holds constructor parameters for a Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type Crate

type Crate struct {
	Rank        int    `json:"rank"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Downloads   int64  `json:"downloads"`
	RecentDown  int64  `json:"recent_downloads"`
	MaxVersion  string `json:"max_version"`
	Updated     string `json:"updated"`
	URL         string `json:"url"`
}

Crate is the primary record for a crate from crates.io. Used by search, top, and crate commands.

type Dep

type Dep struct {
	Name     string `json:"name"`
	Req      string `json:"req"`
	Kind     string `json:"kind"`
	Optional bool   `json:"optional"`
	Features string `json:"features"`
}

Dep is a record for a single dependency of a crate version.

type Keyword

type Keyword struct {
	Keyword     string `json:"keyword"`
	CratesCount int    `json:"crates_cnt"`
}

Keyword is a record for a popular keyword on crates.io.

type Owner

type Owner struct {
	Login string `json:"login"`
	Name  string `json:"name"`
	Kind  string `json:"kind"`
	URL   string `json:"url"`
}

Owner is a record for a crate owner (user or team).

type ReverseDep added in v0.1.2

type ReverseDep struct {
	Rank      int    `json:"rank"`
	Name      string `json:"name"`
	Req       string `json:"req"`
	Kind      string `json:"kind"`
	Downloads int64  `json:"downloads"`
}

ReverseDep is a crate that depends on a given crate (reverse dependency).

type Version

type Version struct {
	Num         string `json:"num"`
	Downloads   int64  `json:"downloads"`
	CreatedAt   string `json:"created_at"`
	IsYanked    bool   `json:"is_yanked"`
	License     string `json:"license"`
	RustVersion string `json:"rust_version"`
}

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