2022-05-18 00:55:19 +09:00
|
|
|
# workers [](https://pkg.go.dev/github.com/syumai/workers)
|
2022-05-18 00:04:37 +09:00
|
|
|
|
|
|
|
* `workers` is a package to run an HTTP server written in Go on [Cloudflare Workers](https://workers.cloudflare.com/).
|
|
|
|
* This package can easily serve *http.Handler* on Cloudflare Workers.
|
|
|
|
|
|
|
|
## Features
|
|
|
|
|
|
|
|
* [x] serve http.Handler
|
|
|
|
* [ ] environment variables (WIP)
|
|
|
|
* [ ] KV (WIP)
|
|
|
|
* [ ] R2 (WIP)
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
```
|
|
|
|
go get github.com/syumai/workers
|
|
|
|
```
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
implement your http.Handler and give it to `workers.Serve()`.
|
|
|
|
|
|
|
|
```go
|
|
|
|
func main() {
|
|
|
|
var handler http.HandlerFunc = func (w http.ResponseWriter, req *http.Request) { ... }
|
2022-05-18 00:07:25 +09:00
|
|
|
workers.Serve(handler)
|
2022-05-18 00:04:37 +09:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
or just call `http.Handle` and `http.HandleFunc`, then invoke `workers.Serve()` with nil.
|
|
|
|
|
|
|
|
```go
|
|
|
|
func main() {
|
|
|
|
http.HandleFunc("/hello", func (w http.ResponseWriter, req *http.Request) { ... })
|
2022-05-18 00:21:08 +09:00
|
|
|
workers.Serve(nil) // if nil is given, http.DefaultServeMux is used.
|
2022-05-18 00:04:37 +09:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-05-18 00:16:28 +09:00
|
|
|
For concrete examples, see `examples` directory.
|
|
|
|
Currently, all examples use tinygo instead of Go due to binary size issues.
|
2022-05-18 00:04:37 +09:00
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
MIT
|
|
|
|
|
|
|
|
## Author
|
|
|
|
|
|
|
|
syumai
|