freedictionary

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package freedictionary is the library behind the freedictionary command line: the HTTP client, request shaping, and the typed data models for the Free Dictionary API (api.dictionaryapi.dev).

The API requires no authentication. A polite User-Agent and 100 ms pacing between requests keeps the client within the free-tier rate limits.

Index

Constants

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

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the Free Dictionary API over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Lookup

func (c *Client) Lookup(ctx context.Context, word string) ([]Definition, error)

Lookup looks up a word and returns one Definition per (meaning x definition) combination. On 404 it returns an error with the message "no definitions found for %q".

type Config

type Config struct {
	BaseURL string
	Rate    time.Duration
	Retries int
	Timeout time.Duration
}

Config holds all tunable parameters for the Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Definition

type Definition struct {
	Word         string `kit:"id" json:"word"`
	PartOfSpeech string `json:"part_of_speech"`
	Definition   string `json:"definition"`
	Example      string `json:"example"`
	Synonyms     string `json:"synonyms"` // comma-joined, up to 5
	Phonetic     string `json:"phonetic"`
}

Definition is one record produced by the Lookup call. Each entry in the API response, times each meaning, times each definition yields one Definition record.

type Domain

type Domain struct{}

Domain is the Free Dictionary driver.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any input into the canonical (type, id). Every non-empty string is treated as a word to look up.

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.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns a reference URL for a word.

func (Domain) Register

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

Register installs the client factory and every operation onto app.

Jump to

Keyboard shortcuts

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