pluginpack

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package pluginpack bridges fetcher plugins into the pack scheme registry: every loaded plugin that advertises the fetch capability gets its schemes registered, so knot://libs as a --package value (or as a script source) resolves to a bundle whose files are fetched on demand over the plugin protocol.

The host never persists what a plugin serves. Content is held in memory for the lifetime of the bundle's file system and revalidated with the plugin's own validators; nothing reaches the package cache on disk. A plugin that wants caching across runs does it behind its fetcher, where the backend's credentials and freshness rules already live.

Host applications that embed scriptling use the same path the CLI does:

bridge := pluginpack.New(pluginpack.Options{
    Context: ctx,      // cancels in-flight fetches
    Manager: manager,  // a plugin.Manager with its plugins already loaded
})
if err := bridge.Register(); err != nil { ... }
defer bridge.Close()   // releases the schemes for the next set of plugins

bundles, err := bridge.DeclaredBundles(nil)  // packages plugins declare
loader := pack.NewLoader()
for _, b := range bundles { loader.AddBundle(b) }
bootstrap.ApplyPackLoader(p, loader)

A Bridge owns the schemes it registered and releases them on Close, so a host can reload its plugins without restarting the process.

Index

Constants

View Source
const DefaultDirTTL = 30 * time.Second

DefaultDirTTL is how long a fetcher's directory listing is reused before it is fetched again. Long-lived hosts pick up files that appear in a served directory without a restart; short runs never notice the difference.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bridge

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

Bridge connects a plugin.Manager's fetcher plugins to a pack.SchemeRegistry. It is safe for concurrent use.

func New

func New(opts Options) *Bridge

New creates a Bridge. It does not touch the scheme registry; call Register.

func (*Bridge) Bundles

func (b *Bridge) Bundles() ([]*pack.Bundle, error)

Bundles opens the library bundle of every fetch-capable plugin — the <scheme>://libs source each plugin attaches automatically, with the standard layout. Add the result to a pack.Loader ahead of explicit --package bundles so explicit sources shadow plugin libraries.

func (*Bridge) Close

func (b *Bridge) Close() error

Close releases every scheme this bridge registered. It does not close the plugin manager — the host owns that. Close is safe to call more than once, and bundles opened through the bridge stop working once it returns.

func (*Bridge) FetchScript

func (b *Bridge) FetchScript(ctx context.Context, source string) ([]byte, error)

FetchScript reads a scheme source that is itself a single script file (knot://myscript). Scripts execute immediately, so every call refetches. ctx bounds the fetch; pass nil to use the bridge's context.

func (*Bridge) Register

func (b *Bridge) Register() error

Register wires every fetch-capable plugin in the manager into the scheme registry. Call it after the manager has loaded its plugins and before any scheme source is opened. Two plugins claiming the same scheme is an error, and a partial registration is rolled back so the bridge is left clean.

func (*Bridge) Schemes

func (b *Bridge) Schemes() []string

Schemes returns the schemes this bridge registered, in sorted order.

type Options

type Options struct {
	// Manager holds the loaded plugins to bridge. Required.
	Manager *plugin.Manager

	// Context bounds every fetch this bridge performs. Cancelling it aborts
	// in-flight reads and listings. Defaults to context.Background().
	Context context.Context

	// Registry is the scheme registry to register into. Defaults to the
	// process-wide pack.DefaultSchemeRegistry().
	Registry *pack.SchemeRegistry

	// DirTTL overrides how long directory listings are reused.
	// Zero means DefaultDirTTL; negative disables listing reuse entirely.
	DirTTL time.Duration
}

Options configures a Bridge.

Jump to

Keyboard shortcuts

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