syumai d8de7fb030
Merge pull request #10 from syumai/add-env
add Getenv helper function
2022-08-02 23:53:55 +09:00
2022-08-02 23:49:42 +09:00
2022-05-18 00:04:37 +09:00
2022-08-02 23:53:11 +09:00
2022-05-18 00:04:37 +09:00
2022-05-20 00:11:47 +09:00
2022-07-31 18:36:08 +09:00
2022-05-18 00:04:37 +09:00
2022-06-18 23:55:27 +09:00
2022-05-30 08:45:36 +09:00
2022-05-29 21:59:00 +09:00
2022-08-02 23:50:18 +09:00
2022-05-20 00:12:54 +09:00
2022-05-20 00:11:47 +09:00
2022-05-20 00:11:47 +09:00
2022-05-18 00:04:37 +09:00

workers Go Reference

  • workers is a package to run an HTTP server written in Go on Cloudflare Workers.
  • This package can easily serve http.Handler on Cloudflare Workers.
  • Caution: This is an experimental project.

Features

  • serve http.Handler
  • R2
    • Head
    • Get
    • Put
    • Delete
    • List
    • Options for R2 methods
  • KV
    • Get
    • List
    • Put
    • Delete
    • Options for KV methods
  • Cache API
  • Durable Objects
  • Environment variables

Installation

go get github.com/syumai/workers

Usage

implement your http.Handler and give it to workers.Serve().

func main() {
	var handler http.HandlerFunc = func (w http.ResponseWriter, req *http.Request) { ... }
	workers.Serve(handler)
}

or just call http.Handle and http.HandleFunc, then invoke workers.Serve() with nil.

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

For concrete examples, see examples directory. Currently, all examples use tinygo instead of Go due to binary size issues.

A template repository is also available.

FAQ

How do I deploy a worker implemented in this package?

To deploy a Worker, the following steps are required.

  • Create a worker project using wrangler.
  • Build a Wasm binary.
  • Upload a Wasm binary with a JavaScript code to load and instantiate Wasm (for entry point).

The worker-template-tinygo repository contains all the required files, so I recommend using this template.

License

MIT

Author

syumai

Description
Go package to run an HTTP server on Cloudflare Workers.
Readme 658 KiB
Languages
Go 68.6%
JavaScript 28.1%
Makefile 2.6%
HTML 0.4%
Shell 0.3%