recipes/cloudflare-workers
Cloudflare Container Workers with Go Fiber
Run a Go Fiber v3 app in a Cloudflare Container Worker with a Worker proxy.
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
- Node.js
- Go 1.27+
- Wrangler CLI
- Docker, which Wrangler uses to build the container image. The Dockerfile needs BuildKit, the default builder of Docker Engine 23 and later and of Docker Desktop
- Cloudflare account with Container Workers access
Getting Started
- Install dependencies:
npm install- Run locally:
npm run dev- Deploy to Cloudflare:
npm run deployProject 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 configurationHow 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)