From 6079b1d963f34ada5c4b25363f2319901e283936 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Sat, 8 Jun 2024 00:01:44 +0200 Subject: feat: Add error handling --- pkg/handler/static/handler.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'pkg/handler/static') diff --git a/pkg/handler/static/handler.go b/pkg/handler/static/handler.go index 5155068..0973d75 100644 --- a/pkg/handler/static/handler.go +++ b/pkg/handler/static/handler.go @@ -10,19 +10,21 @@ import ( "git.gabrielgio.me/cerrado/static" ) -func ServeStaticHandler() (func(w http.ResponseWriter, r *http.Request), error) { +func ServeStaticHandler() (ext.ErrorRequestHandler, error) { staticFs, err := fs.Sub(static.Static, ".") if err != nil { return nil, err } - return func(w http.ResponseWriter, r *http.Request) { + return func(w http.ResponseWriter, r *http.Request) error { var ( f = r.PathValue("file") e = filepath.Ext(f) m = mime.TypeByExtension(e) ) ext.SetMIME(w, m) + w.Header().Add("Cache-Control", "immutable") http.ServeFileFS(w, r, staticFs, f) + return nil }, nil } -- cgit v1.2.3