Documentation
¶
Overview ¶
Package pluginkit provides compile-time plugin infrastructure: a lifecycle contract, a plugin host, and route guarding for plugin namespaces.
Index ¶
- func Protect(handler http.Handler, publicPaths []string, ...) http.Handler
- type Failure
- type Host
- func (h *Host) Migrate(ctx context.Context) error
- func (h *Host) PublicPaths() map[string][]string
- func (h *Host) Routes() map[string]http.Handler
- func (h *Host) Seed(ctx context.Context) error
- func (h *Host) Start(ctx context.Context, stopGrace time.Duration) error
- func (h *Host) StartEach(ctx context.Context) (StartOutcome, error)
- func (h *Host) Stop(ctx context.Context) error
- type MigrationStore
- type MigrationVersioner
- type Migrator
- type MigratorOf
- type Plugin
- type PublicPathProvider
- type RouteProvider
- type Seeder
- type StartOutcome
- type StartedPlugin
- type Step
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 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 ¶
Migrate applies every Migrator plugin's schema in order, past those its store records as current, until one fails.
func (*Host) PublicPaths ¶
PublicPaths returns the session-exempt paths of every PublicPathProvider plugin, keyed by plugin ID.
func (*Host) Routes ¶
Routes returns the HTTP handler of every RouteProvider plugin, keyed by plugin ID.
func (*Host) Seed ¶
Seed asks every Seeder plugin to fill its schema in registration order, stopping at the first failure.
func (*Host) Start ¶
Start migrates and starts every plugin in order, stopping the started ones within stopGrace when one fails.
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
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 ¶
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
StartedPlugin is one plugin whose Start returned nil, and how long that Start took.