mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
30 lines
578 B
Go
30 lines
578 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
|
|
"github.com/syumai/workers"
|
|
"github.com/syumai/workers/cloudflare"
|
|
"github.com/syumai/workers/cloudflare/fetch"
|
|
)
|
|
|
|
func main() {
|
|
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
|
bind := cloudflare.GetBinding("hello")
|
|
fc := fetch.NewClient(fetch.WithBinding(bind))
|
|
|
|
hc := fc.HTTPClient(fetch.RedirectModeFollow)
|
|
res, err := hc.Do(req)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
io.Copy(w, res.Body)
|
|
})
|
|
workers.Serve(handler)
|
|
}
|