December 2017
Intermediate to advanced
316 pages
6h 58m
English
Path Prefix is a wildcard for matching after a defined path. The general use case is when we serve files from our static folder and all URLs should be served as-is. From the official Mux documentation, we can use this for serving static files. This is the Mux version of the static file server that we created in the preceding program using httprouter:
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("/tmp/static"))))
This can serve all kinds of files in the directory:
http://localhost:8000/static/js/jquery.min.js
Read now
Unlock full access