Skip to content
workers-go
Esc
navigateopen⌘Jpreview
On this page

Quickstart

Create a workers-go project from the Cloudflare template, run it locally, and deploy it.

The fastest way to start is the Deploy to Cloudflare button, which creates and deploys a project for you — no local setup required.

Deploy to Cloudflare

To create a project manually, follow the steps below.

Requirements

  • Node.js (and npm)
  • Go 1.24.0 or later

Create a project

Create a new Worker project

Scaffold a project from the worker-go template.

npm create cloudflare@latest -- --template github.com/syumai/workers-go/_templates/cloudflare/worker-go

For a smaller Wasm binary, use the TinyGo template instead. It requires TinyGo 0.42.0 or later — TinyGo 0.41.x cannot build net/http for Wasm.

npm create cloudflare@latest -- --template github.com/syumai/workers-go/_templates/cloudflare/worker-tinygo

Initialize Go modules

cd my-app
go mod init
go mod tidy

Start the dev server

npm start

Verify the worker

curl http://localhost:8787/hello

You will see “Hello!” as the response.

Write your handler

Implement an http.Handler and pass it to workers.Serve().

package main

import (
	"net/http"

	"github.com/syumai/workers-go"
)

func main() {
	http.HandleFunc("/hello", func(w http.ResponseWriter, req *http.Request) {
		w.Write([]byte("Hello!"))
	})
	workers.Serve(nil) // if nil is given, http.DefaultServeMux is used
}

Deploy

npm run deploy

The build pipeline of the template compiles your Go code to Wasm and copies the runtime assets — see Build and deploy for how it works under the hood.

Was this page helpful?