NoListFileSystem is a custom filesystem implementation. It wraps around a "base" file system. It is mainly used with http.FileServer
so that 404 status code is returned instead of a directory listing.
Instead of copy & pasting this code in all of my projects, I prefer to store it in a dedicated package.
Please check the example folder for a basic example which:
- uses go embed to embed all static assets
- shows how to use NoListFileSystem
- runs an HTTP server to demonstrate the behaviour
$ go run example/main.go
Listening on 127.0.0.1:7474
When the webserver is started, head to static
and a 404 Error will be returned, instead of a directory listing.
- Alex Edwards on How to disable http.FileServer Directory Listings