Skip to content

Instantly share code, notes, and snippets.

@xDarkicex
Created November 5, 2016 01:15
Show Gist options
  • Select an option

  • Save xDarkicex/9bf56342aa6bd038d4620255e47930d7 to your computer and use it in GitHub Desktop.

Select an option

Save xDarkicex/9bf56342aa6bd038d4620255e47930d7 to your computer and use it in GitHub Desktop.
This is sample caching with router golang
func GetRoutes() *httprouter.Router {
router := httprouter.New()
application := controllers.Application{}
router.GET("/", application.Index)
fileServer := http.FileServer(http.Dir("public"))
router.GET("/static/*filepath", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
w.Header().Set("Vary", "Accept-Encoding")
w.Header().Set("Cache-Control", "public, max-age=7776000")
r.URL.Path = p.ByName("filepath")
fileServer.ServeHTTP(w, r)
})
return router
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment