plugin

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package plugin provides a focused plugin registry and supporting helpers.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAlreadyRegistered indicates a plugin with the same name is already registered.
	ErrAlreadyRegistered = errors.New("plugin: already registered")
	// ErrFactoryExists indicates a factory for the given name already exists.
	ErrFactoryExists = errors.New("plugin: factory already exists")
	// ErrFactoryNotFound indicates no factory exists for the requested name.
	ErrFactoryNotFound = errors.New("plugin: factory not found")
)

Functions

This section is empty.

Types

type ExecSandbox

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

ExecSandbox runs a plugin as an external process using a simple JSON-over-stdio protocol.

func NewExecSandbox

func NewExecSandbox(path string, args ...string) *ExecSandbox

NewExecSandbox creates a sandbox around the provided binary path and arguments.

func (*ExecSandbox) Start

func (e *ExecSandbox) Start(ctx context.Context) error

Start launches the external process and waits for a ready signal.

func (*ExecSandbox) Stop

func (e *ExecSandbox) Stop() error

Stop sends a stop command and waits for the external process to exit.

type Factory

type Factory func() Plugin

Factory is a function that creates a new plugin instance.

func LoadSo

func LoadSo(path string) (Factory, error)

LoadSo loads a Go plugin (.so) exposing a PluginFactory symbol.

type FactoryRegistry

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

FactoryRegistry stores plugin factories by name.

func NewFactoryRegistry

func NewFactoryRegistry() *FactoryRegistry

NewFactoryRegistry creates an empty factory registry.

func (*FactoryRegistry) Create

func (f *FactoryRegistry) Create(name string) (Plugin, error)

Create builds a plugin from a registered factory.

func (*FactoryRegistry) Register

func (f *FactoryRegistry) Register(name string, factory Factory) error

Register stores a named factory.

type Plugin

type Plugin interface {
	Name() string
	Start() error
	Stop() error
}

Plugin defines the lifecycle interface for all plugins.

type Registry

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

Registry manages plugin registration and lifecycle in a deterministic order.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty plugin registry.

func (*Registry) DiscoverFromValues

func (r *Registry) DiscoverFromValues(values ...interface{}) int

DiscoverFromValues inspects provided values and registers any that implement Plugin.

func (*Registry) Get

func (r *Registry) Get(name string) (Plugin, bool)

Get returns a plugin and whether it exists.

func (*Registry) Names

func (r *Registry) Names() []string

Names returns registered plugin names in insertion order.

func (*Registry) Register

func (r *Registry) Register(p Plugin) error

Register adds a plugin to the registry.

func (*Registry) StartAll

func (r *Registry) StartAll() []error

StartAll starts plugins in insertion order and returns any collected errors.

func (*Registry) StopAll

func (r *Registry) StopAll() []error

StopAll stops plugins in reverse insertion order and returns any collected errors.

func (*Registry) Unregister

func (r *Registry) Unregister(name string)

Unregister removes a plugin by name.

Jump to

Keyboard shortcuts

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