package handler import ( "git.haelnorr.com/h/golib/hws" "net/http" "git.haelnorr.com/h/golib/hlog" ) // Handles requests for static files, without allowing access to the // directory viewer and returning 404 if an exact file is not found func StaticFS(staticFS *http.FileSystem, logger *hlog.Logger) http.Handler { return http.HandlerFunc( func(w http.ResponseWriter, r *http.Request) { fs, err := hws.SafeFileServer(staticFS) if err != nil { w.WriteHeader(http.StatusInternalServerError) logger.Error().Err(err).Msg("Failed to load file system") return } fs.ServeHTTP(w, r) }, ) }