wasi

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 18 Imported by: 0

README

wasi

Project Badges

WASI runtime for tinywasm — module lifecycle management, host functions (pub/sub, WebSocket relay), and hot-reload support via wazero.

Example

See example/main.go for a full multi-module server setup with middleware.

Docs

  • WEBSOCKET_CHOICE.md — Why we use github.com/coder/websocket for the host runtime
  • ARCHITECTURE.md — Package dependency graph and runtime message flow diagrams
  • WASI_SERVER.md — Full standalone server: WasiServer, Config, New(), Middleware Pipeline, and ServerInterface implementation
  • HANDOFF_PROTOCOL.md — Hot-swap drain sequence and error cases
  • ORIGINAL_CONCEPT.md — Original prototype design (renamed from WASI_SUPORT.md)
  • WASI_STRATEGY.md — Original module lifecycle split design (superseded by WASI_SERVER.md)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HostBuilder added in v0.0.2

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

func NewHostBuilder added in v0.0.2

func NewHostBuilder(b bus.Bus, wsBroadcast func(topic string, msg []byte), logger func(msg ...any)) *HostBuilder

func (*HostBuilder) Build added in v0.0.2

type MiddlewareModule added in v0.0.3

type MiddlewareModule struct {
	Module *Module
	Rule   Rule
}

MiddlewareModule pairs a Module with its routing Rule.

func (*MiddlewareModule) Matches added in v0.0.3

func (mw *MiddlewareModule) Matches(routeID string) bool

Matches reports whether this middleware applies to a given route name.

type Module added in v0.0.2

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

func Load added in v0.0.2

func Load(ctx context.Context, name string, wasmBytes []byte, hb *HostBuilder) (*Module, error)

func (*Module) Close added in v0.0.2

func (m *Module) Close(ctx context.Context) error

func (*Module) Drain added in v0.0.2

func (m *Module) Drain(ctx context.Context, timeout time.Duration) error

func (*Module) Handle added in v0.0.3

func (m *Module) Handle(ctx context.Context, reqPtr, reqLen uint32) (uint32, error)

Handle calls the module's handle() export. Returns the result ptr (into WASM memory). Returns 0, nil if handleFn is nil.

func (*Module) Init added in v0.0.2

func (m *Module) Init(ctx context.Context) error

type Rule added in v0.0.3

type Rule struct {
	All    bool
	Only   []string // apply only to these route names
	Except []string // apply to all except these route names
}

Rule describes which HTTP routes a middleware module applies to. Loaded from a module's rule.txt at startup.

type WasiServer added in v0.0.2

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

func New

func New() *WasiServer

New creates a WasiServer with all defaults. Configure via Set* methods.

func (*WasiServer) Change added in v0.0.2

func (s *WasiServer) Change(string) error

func (*WasiServer) Label added in v0.0.2

func (s *WasiServer) Label() string

func (*WasiServer) MainInputFileRelativePath added in v0.0.3

func (s *WasiServer) MainInputFileRelativePath() string

MainInputFileRelativePath returns an empty string as WASI server doesn't use a main Go file for compilation.

func (*WasiServer) Name added in v0.0.2

func (s *WasiServer) Name() string

func (*WasiServer) NewFileEvent added in v0.0.2

func (s *WasiServer) NewFileEvent(fileName, extension, filePath, event string) error

func (*WasiServer) RefreshUI added in v0.0.2

func (s *WasiServer) RefreshUI()

func (*WasiServer) RegisterRoutes added in v0.0.2

func (s *WasiServer) RegisterRoutes(fn func(*http.ServeMux))

RegisterRoutes appends fn to the internal route list. Called before StartServer; matching the assetmin pattern.

func (*WasiServer) RestartServer added in v0.0.2

func (s *WasiServer) RestartServer() error

func (*WasiServer) SetAppRootDir added in v0.0.2

func (s *WasiServer) SetAppRootDir(dir string) *WasiServer

func (*WasiServer) SetBus added in v0.0.2

func (s *WasiServer) SetBus(b bus.Bus) *WasiServer

func (*WasiServer) SetDrainTimeout added in v0.0.2

func (s *WasiServer) SetDrainTimeout(d time.Duration) *WasiServer

func (*WasiServer) SetExitChan added in v0.0.2

func (s *WasiServer) SetExitChan(ch chan bool) *WasiServer

func (*WasiServer) SetExternalWatcher added in v0.0.3

func (s *WasiServer) SetExternalWatcher(enable bool) *WasiServer

func (*WasiServer) SetLogger added in v0.0.2

func (s *WasiServer) SetLogger(fn func(msg ...any)) *WasiServer

func (*WasiServer) SetModulesDir added in v0.0.2

func (s *WasiServer) SetModulesDir(dir string) *WasiServer

func (*WasiServer) SetOutputDir added in v0.0.2

func (s *WasiServer) SetOutputDir(dir string) *WasiServer

func (*WasiServer) SetPort added in v0.0.2

func (s *WasiServer) SetPort(port string) *WasiServer

func (*WasiServer) SetUI added in v0.0.2

func (s *WasiServer) SetUI(ui interface{ RefreshUI() }) *WasiServer

func (*WasiServer) StartServer added in v0.0.2

func (s *WasiServer) StartServer(wg *sync.WaitGroup)

StartServer starts the server.

func (*WasiServer) StopServer added in v0.0.2

func (s *WasiServer) StopServer() error

func (*WasiServer) SupportedExtensions added in v0.0.2

func (s *WasiServer) SupportedExtensions() []string

func (*WasiServer) UnobservedFiles added in v0.0.2

func (s *WasiServer) UnobservedFiles() []string

func (*WasiServer) Value added in v0.0.2

func (s *WasiServer) Value() string

Jump to

Keyboard shortcuts

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