plugin

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package plugin defines the unified plugin host for huan extensions.

Plugin is the minimal base interface every plugin satisfies. Capability interfaces (e.g. deploy.Deployer) embed Plugin and add domain-specific methods. The Registry holds plugins keyed by Name(); Find[T] returns the subset implementing a given capability.

See docs/adr/0003-unified-plugin-system.md for the architectural decisions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Find

func Find[T any](r *Registry) []T

Find returns all registered plugins implementing capability T, in registration order. T is typically a capability interface such as deploy.Deployer.

Example:

deployers := plugin.Find[deploy.Deployer](registry)
for _, d := range deployers { ... }

Types

type Plugin

type Plugin interface {
	// Name is the plugin's unique identifier. It matches the yaml key under
	// plugins: (e.g. Name()=="cloudflare" pairs with yaml plugins.cloudflare.*).
	Name() string
}

Plugin is the base interface every plugin satisfies. Capability interfaces (Deployer, future PaymentProvider, etc.) embed Plugin and add methods.

Plugin intentionally has only Name(): config injection happens via the plugin's constructor (e.g. cloudflare.New(cfg)), not via an Init method. Lifecycle hooks (Start/Stop), when needed, live on the specific capability interface rather than the base.

type Registry

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

Registry holds plugins keyed by Name(). The order slice preserves registration order for deterministic iteration in Find[T] and All.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty Registry.

func (*Registry) All

func (r *Registry) All() []Plugin

All returns all registered plugins in registration order. The returned slice is a copy; callers may mutate it without affecting the registry.

func (*Registry) Get

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

Get returns the plugin with the given name and a found flag.

func (*Registry) Names

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

Names returns all registered plugin names in registration order.

func (*Registry) Register

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

Register adds a plugin to the registry. Returns an error if a plugin with the same Name() is already registered — duplicate registration is treated as a programming error rather than silently overwritten.

func (*Registry) SortedNames

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

SortedNames returns registered plugin names in lexicographic order. Useful for CLI listing where deterministic alphabetical output is preferred over registration order.

Jump to

Keyboard shortcuts

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