Documentation
¶
Overview ¶
Package digimon is the library behind the digimon command line: the HTTP client, request shaping, and the typed data models for the Digimon API at digi-api.com.
The Client sets a real User-Agent, paces requests so a busy session stays polite, and retries transient failures (429 and 5xx). Build your endpoint calls and JSON decoding on top of it.
Index ¶
- Constants
- type Client
- func (c *Client) Get(ctx context.Context, url string) ([]byte, error)
- func (c *Client) GetDigimon(ctx context.Context, nameOrID string) (*Digimon, error)
- func (c *Client) ListDigimon(ctx context.Context, limit int) ([]DigimonStub, error)
- func (c *Client) SearchDigimon(ctx context.Context, name string, limit int) ([]DigimonStub, error)
- type Digimon
- type DigimonStub
- type Domain
Constants ¶
const DefaultUserAgent = "digimon/dev (+https://github.com/tamnd/digimon-cli)"
DefaultUserAgent identifies the client to digi-api.com.
const Host = "digi-api.com"
Host is the site this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
HTTP *http.Client
UserAgent 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 the Digimon API over HTTP.
func (*Client) Get ¶
Get fetches url and returns the response body. It paces and retries according to the client settings. The body is read fully and closed here.
func (*Client) GetDigimon ¶
GetDigimon fetches full details for a single Digimon by name or numeric ID.
func (*Client) ListDigimon ¶
ListDigimon returns up to limit Digimon stubs from the first page.
func (*Client) SearchDigimon ¶
SearchDigimon returns up to limit Digimon stubs matching name.
type Digimon ¶
type Digimon struct {
ID int `kit:"id" json:"id"`
Name string `json:"name"`
Level string `json:"level"`
Type string `json:"type"`
Attribute string `json:"attribute"`
Description string `json:"description" kit:"body"`
ReleaseDate string `json:"release_date"`
Image string `json:"image"`
Skills []string `json:"skills"`
NextEvos []string `json:"next_evolutions"`
PriorEvos []string `json:"prior_evolutions"`
}
Digimon is the full record returned by the digimon command.
type DigimonStub ¶
type DigimonStub struct {
ID int `kit:"id" json:"id"`
Name string `json:"name"`
Image string `json:"image"`
}
DigimonStub is the lightweight record returned by list and search.
type Domain ¶
type Domain struct{}
Domain is the Digimon API driver. It carries no state; the per-run client is built by the factory Register hands kit.
func (Domain) Classify ¶
Classify turns any accepted input into the canonical (type, id) pair. A pure numeric string maps to ("id", input); a word-like string maps to ("name", input). Full digi-api.com URLs are unwrapped first.
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.