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 ¶
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 (*Bridge) Bundles ¶
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 ¶
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 ¶
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 ¶
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.
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.