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
- Variables
- type Category
- type Client
- func (c *Client) GetCrate(ctx context.Context, name string) (*Crate, error)
- func (c *Client) ListCategories(ctx context.Context, limit int) ([]Category, error)
- func (c *Client) ListVersions(ctx context.Context, name string, limit int) ([]Version, error)
- func (c *Client) SearchCrates(ctx context.Context, query string, limit int) ([]Crate, error)
- type Config
- type Crate
- type Domain
- type Version
Constants ¶
const Host = "crates.io"
Host is the site this client talks to, and the host the URI driver claims.
Variables ¶
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 (*Client) ListCategories ¶ added in v0.2.0
ListCategories lists crates.io categories, limited to limit results.
func (*Client) ListVersions ¶ added in v0.2.0
ListVersions lists all published versions of a crate, truncated to limit.
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
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.
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.