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
- Variables
- type Category
- type Client
- func (c *Client) Categories(ctx context.Context) ([]Category, error)
- func (c *Client) Crate(ctx context.Context, name string) (Crate, error)
- func (c *Client) Deps(ctx context.Context, name string) ([]Dep, error)
- func (c *Client) Keywords(ctx context.Context) ([]Keyword, error)
- func (c *Client) Owners(ctx context.Context, name string) ([]Owner, error)
- func (c *Client) Search(ctx context.Context, query, sort string, limit int) ([]Crate, error)
- func (c *Client) Top(ctx context.Context, page, limit int) ([]Crate, error)
- func (c *Client) Versions(ctx context.Context, name string) ([]Version, error)
- type Config
- type Crate
- type Dep
- type Keyword
- type Owner
- type Version
Constants ¶
const DefaultUserAgent = "crates-cli/dev (+https://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 ¶
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 (*Client) Categories ¶
Categories lists all crates.io categories.
func (*Client) Deps ¶
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) Search ¶
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.
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.
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 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 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.