Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
/ staticHandler Public archive

A layer on top of the stdlib http.ServeFile that restricts directory browsing. Also includes a command line server for quickly serving files from multiple directories under chosen prefixes.

License

Notifications You must be signed in to change notification settings

flowonyx/staticHandler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

staticHandler

A layer on top of the stdlib http.ServeFile that eliminates directory browsing. Also includes a command line server for quickly serving files from multiple directories under chosen prefixes.

When you want to serve files from a directory without an index.html file and you don't want the directory to be browsable, this allows you to easily do that.

Just go get github.com/flowonyx/staticHandler.

For an example of how to use this library, look at cmd/staticsite/main.go.

Basically, staticHandler.NewFileOnlyHandler(root, stripPrefix) returns an http.Handler. The stripPrefix parameter is the string prefix you want to strip off when serving requests. You can leave it as an empty string if you don't want to strip any prefix.

Also of note, is that it will look for a custom error page when there is an error ({error code}.html). It also allows setting the HTML for each error code through the SetErrorPage function. You can also set the ErrorPageHandler to a custom function for serving error pages.

About

A layer on top of the stdlib http.ServeFile that restricts directory browsing. Also includes a command line server for quickly serving files from multiple directories under chosen prefixes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages