Skip to content

Getting Started

  • Go 1.22+go version
  • TinyGobrew install tinygo
  • Zig 0.15+ziglang.org/download
  • wasm-ld — comes with LLVM/Homebrew LLD
  • Node.js 18+ — for wrangler
Terminal window
git clone https://github.com/user/gomode.git
cd gomode
npm install
Terminal window
# Build Zig .o + TinyGo into single WASM binary
npm run build
# Or separately:
npm run build:zig # Zig → zig-abi.o
npm run build:go # TinyGo + zig-abi.o → go.wasm
Terminal window
npm run dev
# → http://localhost:8787

Routes:

  • http://localhost:8787/ — Hello world (Worker mode)
  • http://localhost:8787/simd — SIMD demo (Go calling Zig)
  • http://localhost:8787/json — JSON response
  • http://localhost:8787/do/ — Durable Object mode
worker/src/
worker.ts — Entry point, routes to Worker or DO
go-do.ts — Durable Object runtime
zig-abi/src/
main.zig — Memory mgmt + SIMD exports
simd.zig — WASM SIMD v128 batch operations
go-sdk/
gomode.go — CGo wrappers for Zig functions
zig_abi.h — C header for Zig exports
examples/
hello-worker/ — Example Go handler with SIMD

Create a new directory:

Terminal window
mkdir my-handler && cd my-handler
go mod init my-handler

Add go-sdk dependency:

go.mod
require gomode v0.0.0
replace gomode => ../go-sdk

Write your handler:

package main
import (
"gomode"
"unsafe"
)
const (
tagI32 = 2
tagString = 4
valueSlot = 16
stringHeader = 4
respSize = 3 * valueSlot
)
var respBase uintptr
var respStrings [][]byte
// zerobuf read/write helpers (see examples/hello-worker/main.go)
//export handle_zerobuf
func handleZerobuf(reqBase uint32) uint32 {
path := readZBString(uintptr(reqBase) + 1*valueSlot)
switch path {
case "/":
return writeResponse(200, "text/plain", "Hello!")
case "/sum":
data := []float64{1, 2, 3, 4}
sum := gomode.ZigSimdSumF64(
uint32(uintptr(unsafe.Pointer(&data[0]))),
uint32(len(data)),
)
return writeResponse(200, "text/plain", formatFloat(sum))
default:
return writeResponse(404, "text/plain", "not found")
}
}
func main() {}

Build and run:

Terminal window
cd /path/to/gomode
npm run build:zig
tinygo build -target wasip1 -scheduler=none -gc=leaking \
-ldflags="-extldflags='build/zig-abi.o'" \
-o worker/src/go.wasm /path/to/my-handler
npm run dev