package static import ( "io/fs" "mime" "net/http" "path/filepath" "git.gabrielgio.me/cerrado/pkg/ext" "git.gabrielgio.me/cerrado/static" ) 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) 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 }