dictionary

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

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

View Source
const DefaultUserAgent = "dict/dev (+https://github.com/tamnd/dictionary-cli)"

DefaultUserAgent identifies the client to the API.

View Source
const Host = "api.dictionaryapi.dev"

Host is the canonical hostname for the Free Dictionary API.

Variables

View Source
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 NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client with the given config.

func (*Client) Antonyms

func (c *Client) Antonyms(ctx context.Context, lang, word string, limit int) ([]Synonym, error)

Antonyms returns deduplicated Synonym records (antonyms) for word in lang. If limit > 0, at most limit records are returned.

func (*Client) Define

func (c *Client) Define(ctx context.Context, lang, word string, limit int) ([]Definition, error)

Define returns flattened Definition records for word in lang. If limit > 0, at most limit records are returned.

func (*Client) Examples

func (c *Client) Examples(ctx context.Context, lang, word string, limit int) ([]Example, error)

Examples returns deduplicated Example records for word in lang. If limit > 0, at most limit records are returned.

func (*Client) Phonetics

func (c *Client) Phonetics(ctx context.Context, lang, word string) ([]Phonetic, error)

Phonetics returns Phonetic records for word in lang.

func (*Client) Synonyms

func (c *Client) Synonyms(ctx context.Context, lang, word string, limit int) ([]Synonym, error)

Synonyms returns deduplicated Synonym 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.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

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.

func (Domain) Register added in v0.1.1

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

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.

type Phonetic

type Phonetic struct {
	Text  string `json:"text"`
	Audio string `json:"audio"`
}

Phonetic is the record emitted for phonetics.

type Synonym

type Synonym struct {
	Rank int    `json:"rank"`
	Word string `json:"word"`
	URL  string `json:"url"`
}

Synonym is the record emitted for synonyms and antonyms.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL