Documentation
¶
Overview ¶
Package dictionary is the library behind the dict command: the HTTP client, request shaping, and the typed data models for the Free Dictionary API.
The API at api.dictionaryapi.dev is completely free and requires no authentication. The client sets a real User-Agent, paces requests, and retries 429/5xx with backoff.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) Antonyms(ctx context.Context, lang, word string, limit int) ([]Synonym, error)
- func (c *Client) Define(ctx context.Context, lang, word string, limit int) ([]Definition, error)
- func (c *Client) Examples(ctx context.Context, lang, word string, limit int) ([]Example, error)
- func (c *Client) Phonetics(ctx context.Context, lang, word string) ([]Phonetic, error)
- func (c *Client) Synonyms(ctx context.Context, lang, word string, limit int) ([]Synonym, error)
- type Config
- type Definition
- type Domain
- type Example
- type Phonetic
- type Synonym
Constants ¶
const DefaultUserAgent = "dict/dev (+https://github.com/tamnd/dictionary-cli)"
DefaultUserAgent identifies the client to the API.
const Host = "api.dictionaryapi.dev"
Host is the canonical hostname for the Free Dictionary API.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when the API responds with "No Definitions Found".
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the Free Dictionary API.
func (*Client) Antonyms ¶
Antonyms returns deduplicated Synonym records (antonyms) for word in lang. If limit > 0, at most limit records are returned.
func (*Client) Define ¶
Define returns flattened Definition records for word in lang. If limit > 0, at most limit records are returned.
func (*Client) Examples ¶
Examples returns deduplicated Example records for word in lang. If limit > 0, at most limit records are returned.
type Config ¶
type Config struct {
BaseURL string // default "https://api.dictionaryapi.dev"
UserAgent string // default DefaultUserAgent
Rate time.Duration // default 100ms
Retries int // default 3
Timeout time.Duration // default 15s
}
Config holds constructor parameters.
type Definition ¶
type Definition struct {
Rank int `json:"rank"`
Word string `json:"word"`
PartOfSpeech string `json:"part_of_speech"`
Definition string `json:"definition"`
Example string `json:"example"`
Synonyms string `json:"synonyms"`
}
Definition is the record emitted for definitions.
type Domain ¶ added in v0.1.1
type Domain struct{}
Domain is the Free Dictionary API driver. It carries no state; the per-run client is built by the factory Register hands kit.
func (Domain) Info ¶ added in v0.1.1
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 Example ¶
type Example struct {
Rank int `json:"rank"`
Word string `json:"word"`
Example string `json:"example"`
}
Example is the record emitted for example sentences.