mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
48 lines
930 B
Markdown
48 lines
930 B
Markdown
![]() |
# workers
|
||
|
|
||
|
* `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) { ... }
|
||
|
workers.Serve(handler)
|
||
|
}
|
||
|
```
|
||
|
|
||
|
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) { ... })
|
||
|
workers.Serve(nil) // if nil is given, http.DefaultMux is used.
|
||
|
}
|
||
|
```
|
||
|
|
||
|
for concrete examples, see `examples` directory.
|
||
|
|
||
|
## License
|
||
|
|
||
|
MIT
|
||
|
|
||
|
## Author
|
||
|
|
||
|
syumai
|