Documentation
¶
Overview ¶
Package wasm runs WebAssembly plugins (Extism) behind the plugin.Plugin interface. Each hook becomes a JSON call of the matching export; plugins get persistent storage through store_* host functions and HTTP through Extism's built-in client, limited to their allowed hosts.
Index ¶
- Variables
- func ContractFieldNames() []string
- func LoadWasmPlugins(registry *plugin.Registry, dir string, store plugin.Store)
- func ReadSidecar(wasmPath string) ([]string, error)
- func SidecarPath(wasmPath string) string
- func Validate(path string) (plugin.Info, error)
- func WriteAtomic(path string, data []byte) error
- func WriteSidecar(wasmPath string, allowedHosts []string) error
- type Identity
- type Options
- type Plugin
- func (p *Plugin) AllowedHosts() []string
- func (p *Plugin) Close() error
- func (p *Plugin) DisplayName() string
- func (p *Plugin) Health() string
- func (p *Plugin) Identity() Identity
- func (p *Plugin) Name() string
- func (p *Plugin) OnInit(db *gorm.DB) error
- func (p *Plugin) Pages() []plugin.PageDefinition
- func (p *Plugin) RenderPage(ctx *plugin.HookContext, pageType string) (string, gin.H)
- func (p *Plugin) ScheduledJobs() []plugin.ScheduledJob
- func (p *Plugin) Settings() []plugin.SettingDefinition
- func (p *Plugin) TemplateData(ctx *plugin.HookContext) gin.H
- func (p *Plugin) TemplateFooter(ctx *plugin.HookContext) string
- func (p *Plugin) TemplateHead(ctx *plugin.HookContext) string
- func (p *Plugin) Version() string
Constants ¶
This section is empty.
Variables ¶
var ErrNoIdentity = errors.New("wasm plugin: missing identity export")
ErrNoIdentity is returned when a module has no identity export.
var Exports = []string{"identity", "settings", "pages", "jobs", "template_head", "template_footer", "template_data", "render_page", "run_job", "on_init"}
Exports are the functions a plugin module may export; goblog calls the ones present. The documentation is linted against this list.
var HostFunctions = []string{"store_get", "store_set", "store_delete", "store_list", "posts_list"}
HostFunctions are what goblog offers in the extism:host/user namespace besides the PDK's own logging and http_request.
Functions ¶
func ContractFieldNames ¶
func ContractFieldNames() []string
ContractFieldNames lists the JSON field names of every wire type in the plugin contract, for the documentation lint.
func LoadWasmPlugins ¶
LoadWasmPlugins loads every *.wasm in dir and registers it. A file that fails to load is logged and skipped; a missing dir is not an error.
func ReadSidecar ¶
ReadSidecar returns the allowed hosts declared next to a plugin file; nil when there is no sidecar.
func SidecarPath ¶
SidecarPath returns the sidecar file for a .wasm path.
func Validate ¶
Validate loads a .wasm file with no store or network and reports its identity — what `goblog validate-plugin` prints for wasm files.
func WriteAtomic ¶
WriteAtomic writes via a temp file in the same directory and renames it into place, so a crash never leaves a half-written plugin or sidecar.
func WriteSidecar ¶
WriteSidecar records the allowed hosts for a plugin file.
Types ¶
type Identity ¶
type Identity struct {
Name string `json:"name"`
DisplayName string `json:"display_name"`
Version string `json:"version"`
}
Identity is what the mandatory identity export returns.
type Options ¶
type Options struct {
Store plugin.Store // nil → writes fail, reads are empty
AllowedHosts []string // hosts the plugin may reach over HTTP; nil → none
Logf func(format string, args ...any) // nil → log.Printf
Posts func(limit int) ([]plugin.Post, error) // posts_list source; nil → always empty
// NoCache skips the shared compilation cache — for one-off loads such
// as validation, so the compiled code is freed on Close.
NoCache bool
}
Options configure a loaded plugin.
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin is a loaded WebAssembly plugin. It implements plugin.Plugin.
func LoadBytes ¶
LoadBytes instantiates a plugin from module bytes and reads its identity, settings, pages and jobs once.
func (*Plugin) AllowedHosts ¶
AllowedHosts returns the hosts this instance may reach.
func (*Plugin) DisplayName ¶
func (*Plugin) Health ¶
Health reports the instance state for the admin page: "busy" while another call holds it, "closed" when it was closed (timeout or exit) and not re-created yet, otherwise "ok".
func (*Plugin) OnInit ¶
OnInit calls on_init with the plugin's current settings: the declared defaults overlaid with whatever is stored for it (see initInput).
func (*Plugin) Pages ¶
func (p *Plugin) Pages() []plugin.PageDefinition
func (*Plugin) RenderPage ¶
RenderPage maps the render_page result onto goblog's page rendering: html → page_content.html; template+data → passed through; raw → written directly. Errors and unknown shapes decline the request (404 upstream).
func (*Plugin) ScheduledJobs ¶
func (p *Plugin) ScheduledJobs() []plugin.ScheduledJob
func (*Plugin) Settings ¶
func (p *Plugin) Settings() []plugin.SettingDefinition
func (*Plugin) TemplateData ¶
func (p *Plugin) TemplateData(ctx *plugin.HookContext) gin.H
func (*Plugin) TemplateFooter ¶
func (p *Plugin) TemplateFooter(ctx *plugin.HookContext) string
func (*Plugin) TemplateHead ¶
func (p *Plugin) TemplateHead(ctx *plugin.HookContext) string