Cloudflare Container Workers with Go Fiber
This example demonstrates how to use Go Fiber v3 with Cloudflare Container Workers.
Features
- Go Fiber v3 framework
- Distroless container for minimal attack surface (
gcr.io/distroless/static-debian12) - JSON API response
- Environment variables support
- Logger and Recover middleware
Prerequisites
- Bun
- Go 1.25+
- Wrangler CLI
- Cloudflare account with Container Workers access
Getting Started
- Install dependencies:
bun install
- Run locally:
bun run dev
- Deploy to Cloudflare:
bun run deploy
Project Structure
.
├── src/index.ts # Worker entry point
├── container_src/
│ ├── main.go # Go Fiber application
│ ├── go.mod # Go module file
│ └── go.sum # Go dependencies
├── Dockerfile # Container configuration
└── wrangler.jsonc # Cloudflare Workers configuration
How it Works
- The Worker (TypeScript) receives HTTP requests.
- Requests are forwarded to the Go Fiber container.
- The container responds with JSON data, including environment variables.
Container Configuration
The container is configured with:
- 2-minute sleep timeout for inactivity
- Environment variable
MESSAGEpassed from the container class - Port 8080 (default)