Documentation
¶
Overview ¶
Package pluginhost embeds the Lesstruct WASM plugin host for use by programs that import Lesstruct as a library. A host builds a System from in-memory WASM bytes plus parsed manifests, scoped to one tenant, with its own database handle and HTTP client.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrHookNotFound = errors.New("pluginhost: hook not found") ErrHookExecutionFailed = errors.New("pluginhost: hook execution failed") ErrResourceLimitsExceeded = errors.New("pluginhost: plugin exceeded resource limits") ErrPluginInvalidFormat = errors.New("pluginhost: invalid WASM format") ErrPluginLoadFailed = errors.New("pluginhost: plugin load failed") )
Functions ¶
This section is empty.
Types ¶
type Capabilities ¶
type Capabilities struct {
HTTP []string `toml:"http"`
Database []string `toml:"database"`
RateLimit RateLimitConfig `toml:"rate_limit"`
}
Capabilities mirrors the manifest capabilities section.
type DBExecutor ¶
type DBExecutor interface {
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}
DBExecutor abstracts database access for host functions.
type FailureMode ¶
type FailureMode int
FailureMode determines how hook failures are handled.
const ( FailFast FailureMode = iota LogAndContinue Fallback DefaultFailureMode = FailFast )
func ParseFailureMode ¶
func ParseFailureMode(s string) FailureMode
ParseFailureMode parses a failure mode string.
func (FailureMode) String ¶
func (f FailureMode) String() string
String returns FailureMode as a human-readable string.
type HookData ¶
type HookData struct {
ContentID int `json:"contentId"`
UserID int `json:"userId"`
Title string `json:"title"`
Content string `json:"content"`
Tags []string `json:"tags"`
Status string `json:"status"`
PostType string `json:"postType"`
CustomFields map[string]any `json:"customFields,omitempty"`
}
HookData is the JSON payload sent to and received from plugin hooks.
type HookName ¶
type HookName string
HookName identifies a content lifecycle hook.
const ( HookBeforeSave HookName = "BeforeSaveContent" HookAfterPublish HookName = "AfterPublishContent" HookBeforeDelete HookName = "BeforeDeleteContent" HookAfterCreate HookName = "AfterCreateContent" HookAfterUnpublish HookName = "AfterUnpublishContent" HookOnPluginLoaded HookName = "OnPluginLoaded" DefaultPriority = 100 )
type HookOptions ¶
type HookOptions struct {
FailureMode FailureMode
Priority int
}
HookOptions controls hook registration priority and failure handling.
type HookResult ¶
type HookResult struct {
Title *string `json:"title"`
CustomFields map[string]any `json:"customFields,omitempty"`
}
HookResult is the parse view of a before_save hook's returned JSON.
type HostConfig ¶
type HostConfig struct {
HTTPClient *http.Client
DB DBExecutor
}
HostConfig supplies per-tenant host resources.
type Manifest ¶
type Manifest struct {
Name string `toml:"name"`
Version string `toml:"version"`
MaxMemoryMB int `toml:"max_memory_mb"`
Capabilities Capabilities `toml:"capabilities"`
}
Manifest declares a plugin's capabilities. MaxMemoryMB caps the plugin's linear memory and is enforced per plugin as the minimum of the tenant runtime limit and the manifest value when positive.
func ParseManifest ¶
ParseManifest parses a TOML capability manifest from bytes.
func (Manifest) HasDBPermission ¶
HasDBPermission checks whether Manifest allows a specific db permission.
func (Manifest) HasDatabase ¶
HasDatabase reports whether Manifest declares database permissions.
func (Manifest) IsHTTPURLAllowed ¶
IsHTTPURLAllowed checks whether url is covered by Manifest patterns.
type PluginInfo ¶
PluginInfo describes a loaded plugin.
type PluginSource ¶
PluginSource is one in-memory plugin plus its parsed manifest.
type RateLimitConfig ¶
type RateLimitConfig struct {
RequestsPerMinute int `toml:"requests_per_minute"`
}
RateLimitConfig is reserved for future use. RequestsPerMinute is parsed for forward compatibility but no rate limiting is enforced today.
type RuntimeConfig ¶
type RuntimeConfig struct {
MaxMemoryBytes uint64
MaxExecutionTime time.Duration
Logger func(string)
CompilationCache wazero.CompilationCache
}
RuntimeConfig controls per-tenant WASM execution limits.
type System ¶
type System struct {
// contains filtered or unexported fields
}
System is a per-tenant plugin host built from in-memory sources.
func NewSystem ¶
func NewSystem( ctx context.Context, rtConfig RuntimeConfig, hostConfig HostConfig, sources []PluginSource, hookOpts HookOptions, ) (*System, error)
NewSystem builds a per-tenant System from in-memory sources.
func (*System) Plugins ¶
func (s *System) Plugins() []PluginInfo
Plugins returns the loaded plugins' metadata.