From d0e0c1eb99303e1000140d4b98c610077278dc42 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Sat, 1 Jun 2024 20:20:00 +0200 Subject: ref: Remove mux --- pkg/handler/static/handler.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'pkg/handler/static') diff --git a/pkg/handler/static/handler.go b/pkg/handler/static/handler.go index 6a826cc..a8b4583 100644 --- a/pkg/handler/static/handler.go +++ b/pkg/handler/static/handler.go @@ -7,12 +7,15 @@ import ( "git.gabrielgio.me/cerrado/static" ) -func NewStaticHander(prefix string) (http.Handler, error) { +func ServeStaticHandler() (func(w http.ResponseWriter, r *http.Request), error) { staticFs, err := fs.Sub(static.Static, ".") if err != nil { return nil, err } - handler := http.StripPrefix(prefix, http.FileServer(http.FS(staticFs))) - return handler, nil + return func(w http.ResponseWriter, r *http.Request) { + f := r.PathValue("file") + + http.ServeFileFS(w, r, staticFs, f) + }, nil } -- cgit v1.2.3