package fs import ( "net/http" "strings" "github.com/go-chi/chi" ) func NewHandler(path string) http.HandlerFunc { filesDir := http.Dir(path) return func(w http.ResponseWriter, r *http.Request) { rctx := chi.RouteContext(r.Context()) pathPrefix := strings.TrimSuffix(rctx.RoutePattern(), "/*") fs := http.StripPrefix(pathPrefix, http.FileServer(filesDir)) fs.ServeHTTP(w, r) } }