Cloudflare Worker application written in Go, compiled to WASM, with access to KV, R2, D1, and Durable Objects.
- Go 1.21+
- Wrangler CLI
- Cloudflare account
- Install dependencies:
go mod download- Configure your bindings in
wrangler.toml:- Create and configure KV namespace (need the ID)
- Create an R2 bucket (need the name)
- Create and configure D1 database (need the ID)
- Configure Durable Objects as needed
Build and run locally:
make devDeploy to Cloudflare:
make deployGET /- Root endpoint showing available routesGET /kv?key=<key>- Get value from KVPUT /kv?key=<key>&value=<value>- Set key-value in KVDELETE /kv?key=<key>- Delete key from KVGET /r2?key=<key>- Get object from R2PUT /r2?key=<key>- Put object to R2 (body is the content)GET /d1- Query D1 databaseGET /do- Interact with Durable Object
main.go- Worker handler with KV, R2, D1, and DO exampleswrangler.toml- Cloudflare configurationMakefile- Build commands using workers-assets-gen
- syumai/workers - Go bindings for Cloudflare Workers