Go can compile to WebAssembly, which you can then use from JavaScript in a Browser or similar environments (Node, Deno, Bun etc.). You could also target WASI (WebAssembly System Interface) and run it in a standalone runtime (wazero, wasmtime, Wasmer), but in this example we focus on the Browser use case.
- Compile the
chromem-go
WASM binding to WebAssembly:cd /path/to/chromem-go/wasm
GOOS=js GOARCH=wasm go build -o ../examples/webassembly/chromem-go.wasm
- Copy Go's wrapper JavaScript:
cp $(go env GOROOT)/misc/wasm/wasm_exec.js ../examples/webassembly/wasm_exec.js
- Serve the files
cd ../examples/webassembly
go run github.com/philippgille/serve@latest -b localhost -p 8080
or similar
- Open http://localhost:8080 in your browser