Documentation
¶
Overview ¶
Package fruityvice is the library behind the fruityvice command line: the HTTP client, request shaping, and typed data models for fruityvice.com.
The Client sets a real User-Agent, paces requests, and retries transient failures (429 and 5xx) with exponential backoff. Five operations are provided: list all fruits, get by name, list by family, list by genus, and list by order.
Index ¶
- Constants
- type Client
- func (c *Client) ByFamily(ctx context.Context, family string) ([]Fruit, error)
- func (c *Client) ByGenus(ctx context.Context, genus string) ([]Fruit, error)
- func (c *Client) ByOrder(ctx context.Context, order string) ([]Fruit, error)
- func (c *Client) GetFruit(ctx context.Context, name string) (*Fruit, error)
- func (c *Client) ListAll(ctx context.Context) ([]Fruit, error)
- type Config
- type Domain
- type Fruit
Constants ¶
const Host = "fruityvice.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 {
// contains filtered or unexported fields
}
Client talks to fruityvice.com over HTTP.
func (*Client) ByFamily ¶
ByFamily returns fruits that belong to the given plant family (e.g. Rosaceae).
func (*Client) ByOrder ¶
ByOrder returns fruits that belong to the given plant order (e.g. Rosales).
type Config ¶
type Config struct {
BaseURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds tunable knobs for the HTTP client.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns sensible defaults for production use.
type Domain ¶
type Domain struct{}
Domain is the fruityvice kit driver. It carries no state; the per-run client is built by the factory Register hands to kit.
func (Domain) Classify ¶
Classify turns a reference string into (type, id) without touching the network. A word-like string (fruit name) becomes ("fruit", input). A full fruityvice.com URL extracts the name from the path.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, hostnames, and the identity used in help and version.
type Fruit ¶
type Fruit struct {
ID int `kit:"id" json:"id"`
Name string `json:"name"`
Family string `json:"family"`
Genus string `json:"genus"`
Order string `json:"order"`
Calories float64 `json:"calories"`
Fat float64 `json:"fat"`
Sugar float64 `json:"sugar"`
Carbohydrates float64 `json:"carbohydrates"`
Protein float64 `json:"protein"`
}
Fruit is the output record for all operations. Nutritional fields are flattened from the API's nested nutritions object so they are directly accessible to --fields, --template, and table rendering.