color

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 color is the library behind the color command line: the HTTP client, request shaping, and the typed data models for the Color Pizza API (api.color.pizza).

Index

Constants

View Source
const Host = "api.color.pizza"

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.color.pizza over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) List

func (c *Client) List(ctx context.Context, count int) ([]Color, error)

List fetches all named colors (or up to count if count > 0).

func (*Client) Names

func (c *Client) Names(ctx context.Context, hexValues []string) ([]Color, error)

Names fetches color name(s) for the given hex values (without # prefix). Example: hexValues = []string{"ff0000", "00ff00"}

func (*Client) Palette

func (c *Client) Palette(ctx context.Context, hexValues []string) ([]Color, string, error)

Palette fetches full palette info for the given hex values (without # prefix).

type Color

type Color struct {
	Rank         int     `json:"rank,omitempty"`
	Name         string  `json:"name"`
	Hex          string  `json:"hex"`
	RGB          RGB     `json:"rgb"`
	HSL          HSL     `json:"hsl"`
	Luminance    float64 `json:"luminance"`
	Distance     float64 `json:"distance,omitempty"`
	RequestedHex string  `json:"requestedHex,omitempty"`
}

Color is a single named color entry from the API.

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

type HSL struct {
	H float64 `json:"h"`
	S float64 `json:"s"`
	L float64 `json:"l"`
}

HSL holds the hue, saturation, lightness components of a color.

type RGB

type RGB struct {
	R int `json:"r"`
	G int `json:"g"`
	B int `json:"b"`
}

RGB holds the red, green, blue components of a color.

Jump to

Keyboard shortcuts

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