Update generator (#37)

This commit is contained in:
Jonas Plum
2022-03-12 21:09:10 +01:00
committed by GitHub
parent eced5df7c8
commit d353268cf2
28 changed files with 1303 additions and 1618 deletions

25
generated/api/static.go Executable file
View File

@@ -0,0 +1,25 @@
package api
import (
"io/fs"
"net/http"
"net/http/httputil"
"net/url"
)
func Static(fsys fs.FS) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
http.FileServer(http.FS(fsys)).ServeHTTP(w, r)
}
}
func Proxy(dest string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
u, _ := url.Parse(dest)
proxy := httputil.NewSingleHostReverseProxy(u)
r.Host = r.URL.Host
proxy.ServeHTTP(w, r)
}
}