plugin

package
v0.70.7 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package plugin provides the instance-owned host for compiled-in Dingo plugins. Subsystem service contracts remain in their owning packages; this package only coordinates provider selection, typed construction, and lifecycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyEnvironment

func ApplyEnvironment(
	capability Capability,
	selection *Selection,
	environ []string,
) error

ApplyEnvironment overlays generic plugin environment entries on a YAML selection. CLI provider selectors are intentionally applied by composition after this function, giving selector CLI > environment > YAML precedence.

func EnvironmentPrefix

func EnvironmentPrefix(capability Capability) string

EnvironmentPrefix returns the generic environment prefix for capability.

func MissingProviderError

func MissingProviderError(capability Capability, name string) error

MissingProviderError returns an actionable error for known providers that require the optional-provider build tag.

func Register

func Register[S, C, D any](
	host *Host,
	descriptor Descriptor,
	defaults func() C,
	factory Factory[S, C, D],
) error

Register adds a typed provider to host. defaults is called before strict decoding and may be nil when the zero value is the provider default.

func Resolve

func Resolve[S, D any](
	ctx context.Context,
	host *Host,
	capability Capability,
	name string,
	rawConfig map[string]any,
	deps D,
) (S, error)

Resolve constructs and starts one selected provider, returning its typed service. A provider that fails during startup is stopped before the error is returned. Previously started providers remain active so composition code can unwind them around non-plugin dependents in the correct order.

func ResolveProvider

func ResolveProvider[D any](
	ctx context.Context,
	host *Host,
	capability Capability,
	name string,
	rawConfig map[string]any,
	deps D,
) error

ResolveProvider constructs and starts a provider whose service has no in-process consumers. The host still owns its lifecycle, while the provider remains free to use a package-specific service type internally. This is useful for endpoint capabilities that only need to be started and stopped.

Types

type Capability

type Capability string

Capability is a stable identifier for a pluggable subsystem.

const (
	CapabilityStorageBlob     Capability = "storage.blob"
	CapabilityStorageMetadata Capability = "storage.metadata"
	CapabilityMempool         Capability = "mempool"
	CapabilityAPIBlockfrost   Capability = "api.blockfrost"
	CapabilityAPIMesh         Capability = "api.mesh"
	CapabilityAPIUtxorpc      Capability = "api.utxorpc"
)

func (Capability) Valid

func (c Capability) Valid() bool

Valid reports whether c is a capability supported by this platform.

type Descriptor

type Descriptor struct {
	Capability  Capability
	Name        string
	Description string
}

Descriptor describes a compiled-in provider.

type Factory

type Factory[S, C, D any] func(context.Context, C, D) (S, Instance, error)

Factory constructs a typed service and its lifecycle from typed configuration and dependencies.

type Host

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

Host is an application-owned provider registry and lifecycle coordinator. A Host is safe for concurrent listing and resolution.

func NewHost

func NewHost() *Host

NewHost returns an empty plugin host.

func (*Host) Providers

func (h *Host) Providers() []Descriptor

Providers returns all registered providers in capability/name order.

func (*Host) Stop

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

Stop stops all successfully started providers in reverse order. It is idempotent; subsequent calls return the first call's result.

func (*Host) StopCapability

func (h *Host) StopCapability(
	ctx context.Context,
	capability Capability,
) error

StopCapability stops successfully started providers for one capability in reverse start order. It is idempotent and leaves other capabilities active, allowing composition code to preserve dependencies on non-plugin services.

func (*Host) ValidateSelection

func (h *Host) ValidateSelection(
	capability Capability,
	name string,
	rawConfig map[string]any,
) error

ValidateSelection verifies that a provider exists and its configuration decodes strictly, without constructing or starting it.

type Instance

type Instance interface {
	Start(context.Context) error
	Stop(context.Context) error
}

Instance is the lifecycle owned by a Host. Start and Stop must honor the supplied context. Stop implementations should be safe to call more than once; Host also guarantees that it invokes each successful instance once.

type Lifecycle

type Lifecycle struct {
	StartFunc func(context.Context) error
	StopFunc  func(context.Context) error
}

Lifecycle adapts functions to Instance.

func (Lifecycle) Start

func (l Lifecycle) Start(ctx context.Context) error

func (Lifecycle) Stop

func (l Lifecycle) Stop(ctx context.Context) error

type Selection

type Selection struct {
	Provider string         `yaml:"provider"`
	Config   map[string]any `yaml:"config"`
}

Selection is the canonical configuration for one capability.

Jump to

Keyboard shortcuts

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