dogapi

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: 11 Imported by: 0

Documentation

Overview

Package dogapi is the library behind the dogapi command line: the HTTP client, request shaping, and typed data models for the Dog CEO's Dog API (dog.ceo).

No API key is required. The client paces requests and retries on transient errors so a busy session stays polite.

Index

Constants

View Source
const Host = "dog.ceo"

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Breed

type Breed struct {
	Name      string `kit:"id" json:"name"`
	SubBreeds string `json:"sub_breeds"` // comma-joined list of sub-breed names, or "" if none
}

Breed is a single dog breed entry.

type Client

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

Client talks to dog.ceo over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) ListBreeds

func (c *Client) ListBreeds(ctx context.Context) ([]Breed, error)

ListBreeds fetches all dog breeds sorted alphabetically.

func (*Client) ListImages

func (c *Client) ListImages(ctx context.Context, breed, subBreed string, limit int) ([]Image, error)

ListImages fetches all images for a breed (and optional sub-breed), then applies the client-side limit.

func (*Client) Random

func (c *Client) Random(ctx context.Context, breed, subBreed string, count int) ([]Image, error)

Random fetches count random dog images. breed and subBreed are optional. count must be >= 1.

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.

type Domain

type Domain struct{}

Domain is the dogapi driver.

func (Domain) Classify

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

Classify turns an input into the canonical (type, id).

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 the live https URL for a (type, id).

func (Domain) Register

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

Register installs the client factory and every operation onto app.

type Image

type Image struct {
	URL   string `kit:"id" json:"url"`
	Breed string `json:"breed"` // extracted from URL path or set from flag
}

Image is a single dog image entry.

Jump to

Keyboard shortcuts

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