pluginkit

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package pluginkit provides compile-time plugin infrastructure: a lifecycle contract, a plugin host, and route guarding for plugin namespaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Protect

func Protect(handler http.Handler, publicPaths []string, wrap func(http.Handler) http.Handler) http.Handler

Protect wraps a plugin handler in the caller-supplied middleware and serves the plugin's declared public paths untouched (exact match, per PublicPathProvider).

Types

type Failure added in v0.8.0

type Failure struct {
	ID   string
	Step Step
	// Panicked is true only for a panic this step recovered, never for an error that merely holds one.
	Panicked bool
	Err      error
}

Failure is one step one plugin failed, or was still waiting for when the context ended.

type Host

type Host struct {
	// contains filtered or unexported fields
}

Host starts and stops a fixed set of plugins.

func NewHost

func NewHost(plugins ...Plugin) *Host

NewHost returns a Host managing plugins. It panics when two plugins share an ID.

func NewHostWithMigrationStore added in v0.8.0

func NewHostWithMigrationStore(store MigrationStore, migratorOf MigratorOf, plugins ...Plugin) (*Host, error)

NewHostWithMigrationStore returns a Host whose migrations skip every plugin store records as current.

func (*Host) Migrate

func (h *Host) Migrate(ctx context.Context) error

Migrate applies every Migrator plugin's schema in order, past those its store records as current, until one fails.

func (*Host) PublicPaths

func (h *Host) PublicPaths() map[string][]string

PublicPaths returns the session-exempt paths of every PublicPathProvider plugin, keyed by plugin ID.

func (*Host) Routes

func (h *Host) Routes() map[string]http.Handler

Routes returns the HTTP handler of every RouteProvider plugin, keyed by plugin ID.

func (*Host) Seed

func (h *Host) Seed(ctx context.Context) error

Seed asks every Seeder plugin to fill its schema in registration order, stopping at the first failure.

func (*Host) Start

func (h *Host) Start(ctx context.Context, stopGrace time.Duration) error

Start migrates and starts every plugin in order, stopping the started ones within stopGrace when one fails.

func (*Host) StartEach added in v0.8.0

func (h *Host) StartEach(ctx context.Context) (StartOutcome, error)

StartEach migrates then starts each plugin on its own past any failure, stopping none, and errs only on a store read.

func (*Host) Stop

func (h *Host) Stop(ctx context.Context) error

Stop stops every plugin in reverse registration order, continuing past failures and returning them joined.

type MigrationStore added in v0.8.0

type MigrationStore interface {
	// Versions returns every recorded version, keyed by plugin id, in one read.
	Versions(ctx context.Context) (map[string]string, error)
	// Record stores version as the one plugin id has now applied.
	Record(ctx context.Context, id, version string) error
}

MigrationStore is an application's record of the migration version each plugin last applied.

type MigrationVersioner added in v0.8.0

type MigrationVersioner interface {
	// MigrationVersion returns the version of the schema, which a host compares as an opaque string.
	MigrationVersion() (string, error)
}

MigrationVersioner is implemented by a Migrator whose schema reports a version a host can compare.

type Migrator

type Migrator interface {
	// Migrate applies the plugin's schema, returning by the time ctx ends.
	Migrate(ctx context.Context) error
}

Migrator is implemented by plugins that own database schema, which a host migrates before starting any plugin, and which a host with a MigrationStore skips while its recorded version is current.

type MigratorOf added in v0.8.0

type MigratorOf func(Plugin) (Migrator, bool)

MigratorOf returns the Migrator that applies a plugin's schema for it, and false when the plugin's own applies.

type Plugin

type Plugin interface {
	ID() string
	// Start readies the plugin, returning by the time ctx ends, and may run again after Stop.
	Start(ctx context.Context) error
	// Stop releases what the plugin holds by the time ctx ends, whether or not Start ran, and may run more than once.
	Stop(ctx context.Context) error
}

Plugin is an independently addable unit of functionality with a managed lifecycle.

type PublicPathProvider

type PublicPathProvider interface {
	// PublicPaths returns those paths, whether or not Start ran or worked.
	PublicPaths() []string
}

PublicPathProvider is implemented by plugins declaring namespace-relative paths that must stay reachable without a session. Paths match exactly, for every HTTP method, and all else stays protected.

type RouteProvider

type RouteProvider interface {
	// Routes returns the plugin's handler, whether or not Start ran or worked.
	Routes() http.Handler
}

RouteProvider is implemented by plugins that expose HTTP endpoints under their own namespace.

type Seeder

type Seeder interface {
	Seed(ctx context.Context) error
}

Seeder is implemented by plugins that can fill their own schema with development data, which the host asks for outside the start path.

type StartOutcome added in v0.8.0

type StartOutcome struct {
	Started []StartedPlugin
	Failed  []Failure
}

StartOutcome is what Host.StartEach answers, both lists in registration order, a failed record beside its start.

type StartedPlugin added in v0.8.0

type StartedPlugin struct {
	ID   string
	Took time.Duration
}

StartedPlugin is one plugin whose Start returned nil, and how long that Start took.

type Step added in v0.8.0

type Step string

Step names the part of a plugin's boot a Failure happened in.

const (
	// StepMigrate is the migration pass, and a plugin that fails it does not start.
	StepMigrate Step = "migrate"
	// StepRecord is the note of a migration that ran, and a plugin that fails it still starts.
	StepRecord Step = "record"
	// StepStart is a plugin's Start.
	StepStart Step = "start"
)

Directories

Path Synopsis
graphwire module
Package wire generates plugin wiring and an optional registry from manifests and updates an optional package.json.
Package wire generates plugin wiring and an optional registry from manifests and updates an optional package.json.

Jump to

Keyboard shortcuts

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