wasm

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func WithMemoryLimitMB added in v0.11.0

func WithMemoryLimitMB(mb int) LoadOption

WithMemoryLimitMB sets the maximum memory in megabytes, capped at the wasm32 maximum of 4GB. mb <= 0 keeps the default.

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) SetCallTimeout added in v0.11.0

func (p *WASMPlugin) SetCallTimeout(d time.Duration)

SetCallTimeout changes the deadline for later calls; 0 means none.

func (*WASMPlugin) Shutdown

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

Shutdown implements plugin.Plugin.

Directories

Path Synopsis
Package wasmtest builds minimal WASM plugin modules for tests, so runtime limits can be exercised without a TinyGo toolchain.
Package wasmtest builds minimal WASM plugin modules for tests, so runtime limits can be exercised without a TinyGo toolchain.

Jump to

Keyboard shortcuts

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