I am attempting to use the Gorilla toolkit\'s mux package to route URLs in a Go web server. Using this question as a guide I have the following Go code:
fu
I have this code here that works quite nice and is re-usable.
func ServeStatic(router *mux.Router, staticDirectory string) {
staticPaths := map[string]string{
"styles": staticDirectory + "/styles/",
"bower_components": staticDirectory + "/bower_components/",
"images": staticDirectory + "/images/",
"scripts": staticDirectory + "/scripts/",
}
for pathName, pathValue := range staticPaths {
pathPrefix := "/" + pathName + "/"
router.PathPrefix(pathPrefix).Handler(http.StripPrefix(pathPrefix,
http.FileServer(http.Dir(pathValue))))
}
}
router := mux.NewRouter()
ServeStatic(router, "/static/")