mirror of
https://github.com/imjasonh/gocf
synced 2026-07-07 02:22:17 +00:00
1.4 KiB
1.4 KiB
gocf - Cloudflare Workers in Go
Cloudflare Worker application written in Go, compiled to WASM, with access to KV, R2, D1, and Durable Objects.
Prerequisites
- Go 1.21+
- Wrangler CLI
- Cloudflare account
Setup
- 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
Development
Build and run locally:
make dev
Deployment
Using Wrangler CLI
Deploy to Cloudflare:
make deploy
API Endpoints
GET /- 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
Project Structure
main.go- Worker handler with KV, R2, D1, and DO exampleswrangler.toml- Cloudflare configurationMakefile- Build commands using workers-assets-gen
Resources
- syumai/workers - Go bindings for Cloudflare Workers