adviceslip

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 adviceslip is the library behind the adviceslip command line: the HTTP client, request shaping, and typed data models for api.adviceslip.com.

The Client sets a real User-Agent, paces requests, and retries transient failures (429 and 5xx) with exponential backoff. Two operations are provided: get a random advice slip and search for slips by keyword.

Index

Constants

View Source
const BaseURL = "https://" + Host

BaseURL is the root every request is built from.

View Source
const Host = "api.adviceslip.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 api.adviceslip.com over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Random

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

Random returns a single random advice slip.

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string, limit int) ([]Slip, error)

Search returns advice slips matching the query. Returns an empty slice (not an error) when the API reports no results. Limit is applied client-side.

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 adviceslip 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 slip id into (type, id).

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

func (Domain) Register

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

Register installs the client factory and all operations onto app.

type Slip

type Slip struct {
	ID     int    `json:"id"`
	Advice string `json:"advice"`
}

Slip is a single piece of advice returned by the API.

Jump to

Keyboard shortcuts

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