January 2018
Intermediate to advanced
340 pages
8h 6m
English
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")))
Read now
Unlock full access