Documentation
¶
Index ¶
- type DiscoveredPlugin
- type Loader
- func (l *Loader) DiscoverAll() (int, error)
- func (l *Loader) Discovered() []string
- func (l *Loader) DiscoveredPlugins() []*DiscoveredPlugin
- func (l *Loader) EnsureLoaded(ctx context.Context, name string) error
- func (l *Loader) LoadAll(ctx context.Context) (int, []error)
- func (l *Loader) LoadOrReload(ctx context.Context, name string) error
- func (l *Loader) LoadWASM(ctx context.Context, name string) error
- func (l *Loader) LoadWASMFromPath(ctx context.Context, path string) error
- func (l *Loader) Reload(ctx context.Context, name string) error
- func (l *Loader) StopWatch()
- func (l *Loader) Unload(ctx context.Context, name string) error
- func (l *Loader) WatchDir(ctx context.Context) error
- type LoaderOption
- type PluginManifest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DiscoveredPlugin ¶
type DiscoveredPlugin struct {
Name string // Derived from filename or manifest
Path string // Full path to .wasm file or plugin directory
Type string // "wasm" or "grpc"
Loaded bool // Whether it's been loaded
LoadedAt time.Time
}
DiscoveredPlugin holds info about a plugin found but not yet loaded.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader handles discovery and loading of plugins from the filesystem.
func NewLoader ¶
func NewLoader(pluginDir string, manager *plugin.Manager, logger *slog.Logger, opts ...LoaderOption) *Loader
NewLoader creates a plugin loader for the given directory.
func (*Loader) DiscoverAll ¶
DiscoverAll scans the plugin directory and records available plugins without loading them. Discovers both .wasm files and gRPC plugins (directories with plugin.yaml).
func (*Loader) Discovered ¶
Discovered returns the names of discovered (but possibly not loaded) plugins. Implements plugin.LazyLoader interface.
func (*Loader) DiscoveredPlugins ¶
func (l *Loader) DiscoveredPlugins() []*DiscoveredPlugin
DiscoveredPlugins returns detailed info about discovered plugins.
func (*Loader) EnsureLoaded ¶
EnsureLoaded loads a plugin by name if not already loaded (for lazy loading).
Uses the manager's registry as the source of truth for "already loaded" rather than the discovered[].Loaded cache flag. The flag is maintained by several disjoint code paths (LoadAll, Reload, the fsnotify Remove branch, etc.) and can drift from reality — in particular, some reload/ replace flows update the manager's registry without touching the flag, and vice versa. If EnsureLoaded trusts the flag alone it can either:
- Treat a not-loaded plugin as loaded and return early (user-visible functionality silently missing from a dashboard/widget call).
- Treat an already-loaded plugin as not-loaded and try to spawn a second instance, which collides with the running one (for gRPC plugins that own sockets or long-lived state, the duplicate exits within milliseconds with "acceptAndServe error: timeout waiting for accept"), and leaves the manager's routing in a confused state that loses stateful plugin data.
Checking manager.Get() makes the wrong duplicate-spawn path impossible: if the plugin is registered in the manager, it IS loaded, full stop. We then refresh the flag so future callers short-circuit cheaply.
func (*Loader) LoadAll ¶
LoadAll discovers and loads all plugins from the plugin directory. If lazy loading is enabled, WASM plugins are only discovered (loaded on first call). gRPC plugins are always eagerly loaded because they register routes that must exist before the HTTP server starts accepting requests. Returns the number of successfully loaded/discovered plugins and any errors encountered.
func (*Loader) LoadOrReload ¶ added in v0.7.0
LoadOrReload re-discovers plugins and then loads or reloads the named plugin. Use after uploading a new plugin to ensure it's picked up even if it wasn't present at startup.
func (*Loader) LoadWASMFromPath ¶
LoadWASMFromPath loads a WASM plugin from an arbitrary path.
func (*Loader) Reload ¶
Reload unloads and reloads a plugin by name using atomic replacement to avoid race conditions.
type LoaderOption ¶
type LoaderOption func(*Loader)
LoaderOption configures a Loader.
func WithLazyLoading ¶
func WithLazyLoading() LoaderOption
WithLazyLoading enables lazy loading - plugins are discovered but not loaded until first use.
func WithSignatureVerification ¶ added in v0.7.0
func WithSignatureVerification(trustedKeys []ed25519.PublicKey) LoaderOption
WithSignatureVerification enables plugin binary signature verification. Only plugins signed with one of the trusted keys will be allowed to load.
type PluginManifest ¶ added in v0.7.0
type PluginManifest = pkgplugin.PluginManifest
PluginManifest is an alias for the shared manifest type.