Documentation
¶
Overview ¶
Package mealdb is the library behind the mealdb command line: the HTTP client, request shaping, and the typed data models for TheMealDB.
The free v1 API uses the static key "1" baked into the base URL path (https://www.themealdb.com/api/json/v1/1). No login, no OAuth. The Client sets a polite User-Agent, paces requests, and retries transient failures (429 and 5xx) with a capped backoff.
Index ¶
- Constants
- type Area
- type Category
- type Client
- func (c *Client) Areas(ctx context.Context) ([]Area, error)
- func (c *Client) Categories(ctx context.Context) ([]Category, error)
- func (c *Client) Filter(ctx context.Context, opts FilterOptions) ([]FilterResult, error)
- func (c *Client) Get(ctx context.Context, id string) (Meal, error)
- func (c *Client) Random(ctx context.Context) (Meal, error)
- func (c *Client) Search(ctx context.Context, name string, limit int) ([]Meal, error)
- type Config
- type Domain
- type FilterOptions
- type FilterResult
- type Ingredient
- type Meal
Constants ¶
const Host = "themealdb.com"
Host is the site this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Category ¶
type Category struct {
Rank int `json:"rank"`
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
}
Category is one meal category from TheMealDB.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to TheMealDB over HTTP.
func (*Client) Categories ¶
Categories returns all meal categories. Calls GET /categories.php.
func (*Client) Filter ¶
func (c *Client) Filter(ctx context.Context, opts FilterOptions) ([]FilterResult, error)
Filter returns summary meal records matching the given filter options. At least one of Category or Area must be set.
func (*Client) Get ¶
Get returns a meal by ID. Returns an error if the ID is not found. Calls GET /lookup.php?i={id}.
type Config ¶
type Config struct {
BaseURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds all tunable parameters for the Client.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults for the free v1 API.
type Domain ¶
type Domain struct{}
Domain is the mealdb driver.
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.
type FilterOptions ¶
type FilterOptions struct {
Category string // e.g. "Seafood", "Chicken"
Area string // e.g. "Japanese", "Italian"
Limit int
}
FilterOptions controls which filter is applied.
type FilterResult ¶
type FilterResult struct {
Rank int `json:"rank"`
ID string `json:"id"`
Name string `json:"name"`
Thumbnail string `json:"thumbnail"`
}
FilterResult is a summary meal returned by the filter endpoint. It does not include ingredients; use Get to fetch full details.
type Ingredient ¶
Ingredient is one meal ingredient with its measure.
type Meal ¶
type Meal struct {
Rank int `json:"rank"`
ID string `json:"id"`
Name string `json:"name"`
Category string `json:"category"`
Area string `json:"area"` // cuisine origin
Instructions string `json:"instructions"`
Thumbnail string `json:"thumbnail"`
YouTube string `json:"youtube"`
Ingredients []Ingredient `json:"ingredients"`
}
Meal is one recipe from TheMealDB.