Go compiles to WebAssembly via GOOS=js GOARCH=wasm. The output is a .wasm binary loaded by the standard wasm_exec.js shim and a web/game.js entrypoint.
Setup
No extra installation is needed -- the Go toolchain includes the js/wasm target. You also need the wasm_exec.js shim shipped with your Go installation:
GOOS=js GOARCH=wasm go build -o build/web/game.wasm ./src
cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" build/web/
SDK integration
Go accesses browser globals through syscall/js. Call the two Wavedash SDK functions directly:
package main
import "syscall/js"
func main() {
sdk := js.Global().Get("WavedashJS")
// ... game setup and loop ...
sdk.Call("updateLoadProgressZeroToOne", 1)
sdk.Call("init")
select {} // keep the program running
}
Call updateLoadProgressZeroToOne(...) with intermediate values during async asset loading. init() automatically signals load completion, so call it last.
The web/game.js entrypoint loads wasm_exec.js, instantiates the WASM module, and runs it:
await loadScript("./wasm_exec.js");
const go = new Go();
const result = await WebAssembly.instantiateStreaming(
fetch("./game.wasm"),
go.importObject
);
go.run(result.instance);
Build script
#!/usr/bin/env sh
set -eu
mkdir -p build/web
GOOS=js GOARCH=wasm go build -ldflags="-s -w" -o build/web/game.wasm ./src
cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" build/web/wasm_exec.js
cp web/game.js build/web/game.js
cp web/index.html build/web/index.html
wavedash.toml
game_id = "YOUR_GAME_ID_HERE"
upload_dir = "./build/web"
Other SDK features
Once initialized, WavedashJS also exposes leaderboards, achievements, stats, and user data. Access them the same way via syscall/js:
sdk.Call("uploadLeaderboardScore", "high-scores", 1500, true)
sdk.Call("setAchievement", "first_win")
sdk.Call("storeStats")
user := sdk.Call("getUser")
See the SDK reference for the full API.