catalog

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package catalog fetches and caches the api2convert conversions catalog (the supported categories, targets and their option schemas), so discovery and completion are fast and tolerant of transient offline moments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Catalog

type Catalog struct {
	FetchedAt   time.Time    `json:"fetched_at"`
	Conversions []Conversion `json:"conversions"`
}

Catalog is the cached set of supported conversions.

func Load

func Load(ctx context.Context, c *api2convert.Client, refresh bool, cacheKey string) (*Catalog, error)

Load returns the catalog, using a fresh cached copy when available (unless refresh is set). On a fetch error it falls back to any cached copy, even stale. cacheKey scopes the on-disk cache to an account (e.g. apiKey+"|"+baseURL).

func (*Catalog) Categories

func (c *Catalog) Categories() []string

Categories returns the sorted, unique category names.

func (*Catalog) Filter

func (c *Catalog) Filter(category string) []Conversion

Filter returns conversions in a category (empty = all), sorted by target.

func (*Catalog) HasTarget

func (c *Catalog) HasTarget(target string) bool

HasTarget reports whether the catalog contains the given target.

func (*Catalog) Search

func (c *Catalog) Search(q string) []Conversion

Search returns conversions whose target or category contains q (case-insensitive).

func (*Catalog) Targets

func (c *Catalog) Targets() []string

Targets returns the sorted, unique target format codes.

type Conversion

type Conversion struct {
	ID       string         `json:"id"`
	Category string         `json:"category"`
	Target   string         `json:"target"`
	Options  map[string]any `json:"options,omitempty"`
}

Conversion is one supported conversion in the catalog.

Jump to

Keyboard shortcuts

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