dadjoke

package
v0.1.1 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 dadjoke is the library behind the dadjoke command line: the HTTP client, request shaping, and the typed data models for the dad joke API at icanhazdadjoke.com.

The API is completely open — no authentication or API key required. The Client must send Accept: application/json on every request, otherwise the API returns HTML. It paces requests and retries transient 429 and 5xx failures with exponential backoff.

Index

Constants

View Source
const (
	// Host is the site this client talks to.
	Host = "icanhazdadjoke.com"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client talks to icanhazdadjoke.com over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Get

func (c *Client) Get(ctx context.Context, id string) (Joke, error)

Get returns the dad joke with the given id.

func (*Client) Random added in v0.1.1

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

Random returns a random dad joke.

func (*Client) Search added in v0.1.1

func (c *Client) Search(ctx context.Context, term string, limit, page int) ([]Joke, error)

Search returns dad jokes matching term. limit is capped at 30; pass 0 to use default 20. page is 1-based; pass 0 to use page 1.

type Config added in v0.1.1

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 added in v0.1.1

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Domain

type Domain struct{}

Domain is the dadjoke 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 Joke added in v0.1.1

type Joke struct {
	ID   string `kit:"id" json:"id"`
	Joke string `json:"joke"`
}

Joke is one dad joke.

Jump to

Keyboard shortcuts

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