Help us shape the future of Go! Take the 2026 Go Developer Survey

catalog

package
v1.4.15 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package catalog is the CLI side of contract:plugins.catalog v1 (P7-PLUG-09): the one JSON document at https://plugins.nself.org/catalog.json that lists every plugin of both tiers, its commands and its bundles.

Purpose: fetch the catalog with an ETag cache and an offline fallback, decode it strictly enough to reject a broken publish, and answer the questions the CLI asks of it: search, lookup by slug, which plugin provides a command. Inputs: the catalog URL and a cache directory (default ~/.nself/cache/plugins). Outputs: *Catalog values, the Source they came from, and E115/E116 errors. Constraints: catalog data is display-only. Nothing here installs anything; installs still verify the checksum and signature (P7-PLUG-23). All HTTP goes through internal/httptimeout (Constitution 2.2). The unknown-command path reads the cache only and never touches the network.

Layer: L2 (internal/plugin/**). Imports errs and httptimeout only.

Index

Constants

View Source
const (
	TierFree     = "free"
	TierLicensed = "licensed"
)

Tier values as the catalog writes them.

View Source
const DefaultURL = "https://plugins.nself.org/catalog.json"

DefaultURL is the served catalog (contract:plugins.catalog v1).

View Source
const SchemaVersion = 1

SchemaVersion is the only catalog schema_version this package decodes.

Variables

This section is empty.

Functions

func CommandHint

func CommandHint(cmd string) (slug string, ok bool)

CommandHint returns the slug of the installable catalog plugin whose command is cmd, from the cache alone. ok is false when there is no cache or no such plugin. It never touches the network and never fails the caller.

func DefaultCacheDir

func DefaultCacheDir() string

DefaultCacheDir is where the catalog cache lives: NSELF_PLUGIN_CACHE (the registry cache override) or ~/.nself/cache/plugins. Empty when neither can be resolved; an empty dir disables caching.

Types

type Bundle

type Bundle struct {
	Display string   `json:"display"`
	Tier    string   `json:"tier"`
	Plugins []string `json:"plugins"`
}

Bundle is one bundle: display name, tier and member plugin slugs.

type Catalog

type Catalog struct {
	SchemaVersion int               `json:"schema_version"`
	Generated     string            `json:"_generated,omitempty"`
	GeneratedFrom GeneratedFrom     `json:"generated_from"`
	Plugins       []Entry           `json:"plugins"`
	Bundles       map[string]Bundle `json:"bundles,omitempty"`
}

Catalog is the decoded catalog document. Fields the CLI does not read (counts) are skipped; unknown fields are ignored so an additive publish does not break an older CLI.

func Decode

func Decode(data []byte) (*Catalog, error)

Decode parses and validates a catalog body.

func (*Catalog) FindByCommand

func (c *Catalog) FindByCommand(cmd string) (Entry, bool)

FindByCommand returns the installable plugin whose commands.command is cmd, preferring the free tier when both tiers provide it.

func (*Catalog) Lookup

func (c *Catalog) Lookup(slug string) (Entry, bool)

Lookup returns the entry for slug, preferring the free tier of a tier pair.

func (*Catalog) Search

func (c *Catalog) Search(q, tier string) []Entry

Search returns the entries whose slug, description, category or bundle contains q, case-insensitively. An empty q matches everything. tier narrows to TierFree or TierLicensed; empty means both.

type Commands

type Commands struct {
	Command     string   `json:"command"`
	Subcommands []string `json:"subcommands"`
}

Commands is the CLI command a plugin provides (null when it provides none).

type Entry

type Entry struct {
	Slug        string    `json:"slug"`
	Tier        string    `json:"tier"`
	Version     string    `json:"version"`
	Description string    `json:"description"`
	Category    string    `json:"category"`
	Maturity    string    `json:"maturity"`
	Installable bool      `json:"installable"`
	ServiceKind string    `json:"service_kind"`
	Commands    *Commands `json:"commands"`
	DocsURL     *string   `json:"docs_url"`
	Bundles     []string  `json:"bundles"`
	TierPair    bool      `json:"tier_pair"`
}

Entry is one plugin at one tier. A tier-pair slug appears once per tier.

type GeneratedFrom

type GeneratedFrom struct {
	PluginsRef  string `json:"plugins_ref"`
	BundlesRef  string `json:"bundles_ref"`
	GeneratedAt string `json:"generated_at"`
}

GeneratedFrom records the source refs and time of the publish.

type Result

type Result struct {
	Catalog   *Catalog
	Source    Source
	FetchedAt time.Time
}

Result is a decoded catalog and its provenance. FetchedAt is when the body was last confirmed current (now for the network, the cache mtime otherwise).

func Fetch

func Fetch(ctx context.Context, rawURL, cacheDir string) (Result, error)

Fetch returns the catalog from url, revalidating the cache in cacheDir.

func LoadCached

func LoadCached(dir string) (Result, error)

LoadCached returns the cached catalog without any network access. It is the only read the unknown-command path makes. E115 when there is no usable cache.

func (Result) Note

func (r Result) Note() string

Note is the stderr line to print for a cache-served result, "" otherwise.

type Source

type Source string

Source says where a Result came from.

const (
	// SourceNetwork: the server answered (200, or 304 confirming the cache).
	SourceNetwork Source = "network"
	// SourceCache: the server could not be reached; the stored copy answered.
	SourceCache Source = "cache"
)

Jump to

Keyboard shortcuts

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