Skip to content

imjasonh/gocf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gocf - Cloudflare Workers in Go

Cloudflare Worker application written in Go, compiled to WASM, with access to KV, R2, D1, and Durable Objects.

Prerequisites

Setup

  1. Install dependencies:
go mod download
  1. 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 routes
  • GET /kv?key=<key> - Get value from KV
  • PUT /kv?key=<key>&value=<value> - Set key-value in KV
  • DELETE /kv?key=<key> - Delete key from KV
  • GET /r2?key=<key> - Get object from R2
  • PUT /r2?key=<key> - Put object to R2 (body is the content)
  • GET /d1 - Query D1 database
  • GET /do - Interact with Durable Object

Project Structure

  • main.go - Worker handler with KV, R2, D1, and DO examples
  • wrangler.toml - Cloudflare configuration
  • Makefile - Build commands using workers-assets-gen

Resources

About

Example Cloudflare Worker in Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors