36 lines
831 B
Go
Raw Normal View History

2023-04-02 20:12:24 +09:00
package main
import (
"fmt"
"io"
"net/http"
"github.com/syumai/workers"
"github.com/syumai/workers/cloudflare/fetch"
)
func main() {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
2023-04-02 20:19:48 +09:00
cli := fetch.NewClient()
2023-04-02 20:12:24 +09:00
2023-04-02 20:19:48 +09:00
r, err := fetch.NewRequest(req.Context(), http.MethodGet, "https://api.github.com/repos/syumai/workers/releases/latest", nil)
2023-04-02 20:12:24 +09:00
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
r.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/111.0")
2023-05-28 13:06:16 +09:00
res, err := cli.Do(r, nil)
2023-04-02 20:12:24 +09:00
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
w.Header().Set("content-type", "application/json")
io.Copy(w, res.Body)
})
workers.Serve(handler)
}