colorapi

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 colorapi is the library behind the colorapi command line: the HTTP client, request shaping, and the typed data models for The Color API (thecolorapi.com) — color identification and scheme generation.

Index

Constants

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

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Identify

func (c *Client) Identify(ctx context.Context, hex, rgb, hsl string) (*ColorInfo, error)

Identify resolves a color by one of hex, rgb, or hsl query parameters. Exactly one of hex/rgb/hsl must be non-empty.

func (*Client) Scheme

func (c *Client) Scheme(ctx context.Context, hex, mode string, count int) ([]SchemeColor, error)

Scheme generates a color scheme from a base hex color. mode is one of: monochrome, monochrome-dark, monochrome-light, analogic, complement, analogic-complement, triad, quad. count is the number of colors to return.

type ColorInfo

type ColorInfo struct {
	Name  string `kit:"id" json:"name"`
	Hex   string `json:"hex"`
	RGB   string `json:"rgb"`
	HSL   string `json:"hsl"`
	HSV   string `json:"hsv"`
	CMYK  string `json:"cmyk"`
	Exact bool   `json:"exact_match"`
}

ColorInfo holds the identified properties of a color.

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 colorapi driver.

func (Domain) Classify

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

Classify turns an input into the canonical (type, id). Kit derives URI types from struct names: ColorInfo → colorinfo, SchemeColor → schemecolor.

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 SchemeColor

type SchemeColor struct {
	Hex  string `kit:"id" json:"hex"`
	Name string `json:"name"`
	RGB  string `json:"rgb"`
	HSL  string `json:"hsl"`
}

SchemeColor is one entry in a generated color scheme.

Jump to

Keyboard shortcuts

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