fruityvice

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 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

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

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) ByFamily

func (c *Client) ByFamily(ctx context.Context, family string) ([]Fruit, error)

ByFamily returns fruits that belong to the given plant family (e.g. Rosaceae).

func (*Client) ByGenus

func (c *Client) ByGenus(ctx context.Context, genus string) ([]Fruit, error)

ByGenus returns fruits that belong to the given plant genus (e.g. Malus).

func (*Client) ByOrder

func (c *Client) ByOrder(ctx context.Context, order string) ([]Fruit, error)

ByOrder returns fruits that belong to the given plant order (e.g. Rosales).

func (*Client) GetFruit

func (c *Client) GetFruit(ctx context.Context, name string) (*Fruit, error)

GetFruit returns the fruit with the given name. The name is lowercased before the request because the API accepts any case but lowercase is canonical.

func (*Client) ListAll

func (c *Client) ListAll(ctx context.Context) ([]Fruit, error)

ListAll returns all fruits the API knows about.

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

func (Domain) Classify(input string) (string, string, error)

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.

func (Domain) Locate

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

Locate returns the live API URL for a (type, id) pair.

func (Domain) Register

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

Register installs the client factory and all operations onto app.

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.

Jump to

Keyboard shortcuts

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