catfact

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

Documentation

Overview

Package catfact is the library behind the catfact command line: the HTTP client, request shaping, and the typed data models for the catfact.ninja random cat facts API.

Index

Constants

View Source
const Host = "catfact.ninja"

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 catfact.ninja over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Fact

func (c *Client) Fact(ctx context.Context) (Fact, error)

Fact fetches one random cat fact from /fact. The returned Fact always has Rank=1.

func (*Client) Facts

func (c *Client) Facts(ctx context.Context, limit, page int) ([]Fact, error)

Facts fetches up to limit cat facts from /facts at the given page. limit<=0 defaults to 10; page<=0 defaults to 1. The API supports up to 332 total facts.

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

type Fact struct {
	Rank   int    `json:"rank"`
	Fact   string `json:"fact" kit:"id"`
	Length int    `json:"length"`
}

Fact is a single cat fact entry.

Jump to

Keyboard shortcuts

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