wasm

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package wasm provides a WASM-based plugin runtime using wazero.

WASM plugins are portable, sandboxed modules that communicate with the host via exported functions. This is the default/recommended plugin runtime.

Plugin contract:

  • Export gk_register() -> returns JSON manifest
  • Export gk_call(fn_ptr, fn_len, args_ptr, args_len) -> returns response ptr
  • Export gk_malloc(size) -> allocate memory for host-to-plugin data
  • Export gk_free(ptr) -> free memory

Host provides:

  • gk_host_call(fn_ptr, fn_len, args_ptr, args_len) -> call host API
  • gk_log(level, msg_ptr, msg_len) -> logging

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoadOption

type LoadOption func(*loadOptions)

LoadOption is a functional option for loading WASM plugins.

func WithCallTimeout

func WithCallTimeout(d time.Duration) LoadOption

WithCallTimeout sets the timeout for plugin function calls. Default is 30 seconds.

func WithMemoryLimit

func WithMemoryLimit(pages uint32) LoadOption

WithMemoryLimit sets the maximum memory in pages (64KB each). Default is 256 pages (16MB).

type WASMPlugin

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

WASMPlugin implements plugin.Plugin for WASM modules.

func Load

func Load(ctx context.Context, wasmBytes []byte, opts ...LoadOption) (*WASMPlugin, error)

Load creates a WASM plugin from raw bytes.

func LoadFromFile

func LoadFromFile(ctx context.Context, path string, opts ...LoadOption) (*WASMPlugin, error)

LoadFromFile loads a WASM plugin from a file path.

func (*WASMPlugin) Call

func (p *WASMPlugin) Call(ctx context.Context, fn string, args json.RawMessage) (json.RawMessage, error)

Call implements plugin.Plugin.

func (*WASMPlugin) GKRegister

func (p *WASMPlugin) GKRegister() plugin.GKRegistration

GKRegistration implements plugin.Plugin.

func (*WASMPlugin) Init

func (p *WASMPlugin) Init(ctx context.Context, host plugin.HostAPI) error

Init implements plugin.Plugin.

func (*WASMPlugin) Shutdown

func (p *WASMPlugin) Shutdown(ctx context.Context) error

Shutdown implements plugin.Plugin.

Jump to

Keyboard shortcuts

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