Created
November 5, 2016 01:15
-
-
Save xDarkicex/9bf56342aa6bd038d4620255e47930d7 to your computer and use it in GitHub Desktop.
This is sample caching with router golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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