Skip to content

Latest commit

 

History

History

component

README.md

wasmCloud Component SDK for Go

go.wasmcloud.dev/component builds WebAssembly components from standard Go (1.27+) using componentize-go.

Worlds

The SDK ships two worlds (see wit/world.wit); apps pick one at build time — the default comes from the SDK's componentize-go.toml:

World Target Toolchain
wasip2 (default) sync WASI P2, wasi:http/incoming-handler@0.2.8 stock Go
wasip3 (opt-in) async WASI P3, wasi:http/handler@0.3.0 — streaming bodies, native goroutine concurrency patched Go, auto-installed by componentize-go until golang/go#76775 lands

Both worlds use the same go.bytecodealliance.org/wasi/wasihttp package: the P3 implementation is selected by the componentizego_async build tag, which componentize-go sets automatically when building an async world (merged upstream; with released componentize-go ≤ v0.4.1, set it via GOFLAGS=-tags=componentizego_async).

Usage

package main

import (
	"net/http"

	"go.bytecodealliance.org/wasi/wasihttp"

	// Anchors the SDK in go.mod: it carries the wasmCloud worlds' WIT and
	// componentize-go.toml used at build time.
	_ "go.wasmcloud.dev/component"
)

func init() {
	wasihttp.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Hello!"))
	})
}

func main() {}

Build with go tool componentize-go build (add tool github.com/bytecodealliance/componentize-go to go.mod), or via wash build with the command in .wash/config.yaml. To target the async P3 world: go tool componentize-go -w wasmcloud:component-go/wasip3@0.2.0 build — the same wasihttp API, switched to the P3 implementation by the componentizego_async build tag.

Packages

Everything vendor-neutral lives in go.bytecodealliance.org/wasi — import it directly (there are no wrappers or re-exports here):

Need Import
Serve HTTP (http.Handler), outbound HTTP (http.RoundTripper) go.bytecodealliance.org/wasi/wasihttp
Structured logging (slog.Handler over wasi:logging) go.bytecodealliance.org/wasi/wasilog
Runtime config (wasi:config/store) go.bytecodealliance.org/wasi/wasiconfig

Earlier drafts of this branch had net/wasihttp, net/wasihttp3, log/wasilog, and wasmcloud.GetConfigOrDefault in this module; they are gone — use the go-wasi imports above (wasiconfig.GetOrDefault replaces GetConfigOrDefault). Those packages lived in go.bytecodealliance.org/pkg until its v0.4.0, which kept only the WIT runtime (wit/types, wit/runtime, wit/async) and moved the rest to go-wasi under the same package names.

This module carries what is wasmCloud-specific:

  • the wasmCloud worlds' WIT (wit/) and componentize-go.toml
  • Go packages for the wasmCloud host-plugin interfaces (wasmcloud:secrets, wasmcloud:keyvalue, wasmcloud:messaging, wasmcloud:postgres, wasmcloud:blobstore)
  • host-component support (authoring and calling host components) lives in the sibling go.wasmcloud.dev/plugin module

Telemetry: the former x/wasitel OTLP exporters are retired; wasmCloud v2 serves telemetry through wasi:otel — see the http-otel example.

Components needing more interfaces (e.g. wasi:keyvalue) declare an app-local world merged at build time — see the http-keyvalue-crud example.

Bindings

The wasi:* bindings, and the wasi:http export glue behind wasihttp, live in go.bytecodealliance.org/wasi and are regenerated there. This module's bindings — the wasmCloud capability imports under imports/ and the handler export glue under exports/ — are generated by regenerate_bindings.sh with the same wit-bindgen go-wasi uses (see BUILDING.md); do not edit them by hand.

Previous TinyGo SDK

Versions v0.0.8 and earlier were a TinyGo + wit-bindgen-go SDK; those tags remain importable for existing projects. See MIGRATING.md.