Go/WASM runtime for Cloudflare Workers — the JS↔Go bridge, edge router, and storage adapters that compile into every deployed Worker. Extracted from webtyp/goflare; goflare keeps the build/deploy CLI and imports this repo only for the runtime it ships.
go get webtyp.com/cloudflare/edge
go get webtyp.com/cloudflare/workers
go get webtyp.com/cloudflare/d1
go get webtyp.com/cloudflare/r2
go get webtyp.com/cloudflare/logRequires Go 1.25+ and TinyGo for the //go:build wasm packages.
//go:build wasm
package main
import (
"webtyp.com/cloudflare/d1"
"webtyp.com/cloudflare/edge"
"webtyp.com/fmt"
"webtyp.com/orm"
)
func main() {
db, err := d1.NewEdge("DB")
if err != nil {
fmt.Println("d1:", err)
return
}
// optional DDL sync: ddl.New(db.RawConn(), d1.DDLCompiler(db.RawConn())).Sync(&YourModel{})
r := edge.NewRouter(edge.Config{
// Authn establishes identity before the gate — see edge/edge.go
// Authn: myAuthMiddleware,
// Authorize: myAuthorizer,
})
r.Get("/api/ping", func(ctx edge.Context) {
ctx.Write([]byte("pong"))
}).Public()
r.Get("/api/items/{id}", func(ctx edge.Context) {
id := ctx.Param("id")
ctx.Write([]byte("item " + id))
}).Public()
// register more routes...
edge.Serve(r) // blocks forever, handles every request in this isolate
}Built with goflare (or any bundler reading webtyp.com/cloudflare/assets):
go install webtyp.com/goflare/cmd/goflare@latest
goflare build # → .build/edge.js + .build/edge.wasm
goflare deploy # → Cloudflare Workers APISee webtyp/goflare for the CLI, and docs/ARCHITECTURE.md for the isolate lifecycle contract (context.binding vs shared globals, runtime.ticks ABI).
| Import | Description |
|---|---|
webtyp.com/cloudflare/edge |
Router adapter (router.Router on workers.Handle). For mounting /_routes, see webtyp/router's docs/INTROSPECTION.md. |
webtyp.com/cloudflare/workers |
JS↔Go bridge (Request/Response, Handle/Ready) |
webtyp.com/cloudflare/d1 |
D1 adapter for webtyp/orm (d1.NewEdge, or d1.NewEdgeSession for read replicas via the Sessions API) — see docs/D1.md |
webtyp.com/cloudflare/r2 |
R2 bucket (r2.NewEdge) |
webtyp.com/cloudflare/log |
Edge logging (log.Reject/Fail/Panic) |
webtyp.com/cloudflare/assets |
JS half of runtime (WasmExecJS, RuntimeMJS, WorkerMJS) for bundlers — !wasm |
webtyp.com/env |
Env access (env.Get/Lookup — os+.env vs context.env auto-tag) |
//go:build wasmfiles never import stdlib (fmt,strings,errors). Usewebtyp.com/fmt.- The runtime lives alone — no
os/exec, nonet/httpclient. That stays ingoflare. - Isolate invariants documented in
AGENTS.md— read before touchingworkers/orassets/.
go install webtyp.com/devflow/cmd/gotest@latest
gotestgotest runs go vet, go test -race -cover, and the WASM suite in a real browser (auto-detected via //go:build wasm, wasmbrowsertest under the hood). See webtyp/devflow/docs/GOTEST.md.
See LICENSE.