wasm

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var ErrNoIdentity = errors.New("wasm plugin: missing identity export")

ErrNoIdentity is returned when a module has no identity export.

View Source
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.

View Source
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

func LoadWasmPlugins(registry *plugin.Registry, dir string, store plugin.Store)

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

func ReadSidecar(wasmPath string) ([]string, error)

ReadSidecar returns the allowed hosts declared next to a plugin file; nil when there is no sidecar.

func SidecarPath

func SidecarPath(wasmPath string) string

SidecarPath returns the sidecar file for a .wasm path.

func Validate

func Validate(path string) (plugin.Info, error)

Validate loads a .wasm file with no store or network and reports its identity — what `goblog validate-plugin` prints for wasm files.

func WriteAtomic

func WriteAtomic(path string, data []byte) error

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

func WriteSidecar(wasmPath string, allowedHosts []string) error

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 Load

func Load(path string, opts Options) (*Plugin, error)

Load reads a .wasm file and instantiates it.

func LoadBytes

func LoadBytes(data []byte, opts Options) (*Plugin, error)

LoadBytes instantiates a plugin from module bytes and reads its identity, settings, pages and jobs once.

func (*Plugin) AllowedHosts

func (p *Plugin) AllowedHosts() []string

AllowedHosts returns the hosts this instance may reach.

func (*Plugin) Close

func (p *Plugin) Close() error

Close releases the instance. Calling it again is a no-op.

func (*Plugin) DisplayName

func (p *Plugin) DisplayName() string

func (*Plugin) Health

func (p *Plugin) Health() string

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) Identity

func (p *Plugin) Identity() Identity

Identity returns what the plugin reported.

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) OnInit

func (p *Plugin) OnInit(db *gorm.DB) error

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

func (p *Plugin) RenderPage(ctx *plugin.HookContext, pageType string) (string, gin.H)

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

func (*Plugin) Version

func (p *Plugin) Version() string

Jump to

Keyboard shortcuts

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