Serving static files

Another common web server task is to serve static files. It is worth mentioning the Negroni middleware handler for serving static files. Just add an additional Use() call and pass negroni.NewStatic() to it. Make sure that your static files directory contains only files that clients should access. In most cases, the static files directory contains CSS and JavaScript files for the client. Do not put database backups, configuration files, SSH keys, Git repositories, development files, or anything a client shouldn't have access to. Add the static-file middleware like this:

negroniHandler.Use(negroni.NewStatic(http.Dir("/path/to/static/files")))  

Get Security with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.