diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-06-08 00:01:44 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-06-08 00:01:44 +0200 |
commit | 6079b1d963f34ada5c4b25363f2319901e283936 (patch) | |
tree | f7f93616eb3dacfcebee486fe7542ec3adfb3950 /pkg/handler/static/handler.go | |
parent | e9098e00fb6339b759df5b0df2e086cef8a7ce83 (diff) | |
download | cerrado-6079b1d963f34ada5c4b25363f2319901e283936.tar.gz cerrado-6079b1d963f34ada5c4b25363f2319901e283936.tar.bz2 cerrado-6079b1d963f34ada5c4b25363f2319901e283936.zip |
feat: Add error handling
Diffstat (limited to 'pkg/handler/static/handler.go')
-rw-r--r-- | pkg/handler/static/handler.go | 6 |
1 files changed, 4 insertions, 2 deletions
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 } |