Last active
January 1, 2021 00:07
-
-
Save xeoncross/6a48c341ab0c8a44a67b0ed0e54b9ac3 to your computer and use it in GitHub Desktop.
Example of using httprouter or gorilla/mux to serve static assets (JS, Images, CSS, etc..) cached in the app binary using github.com/markbates/pkger
This file contains 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
// https://github.com/julienschmidt/httprouter | |
router := httprouter.New() | |
router.HandlerFunc("GET", "/", index()) | |
router.Handler("GET", "/static/*filepath", http.StripPrefix("/static/", http.FileServer(pkger.Dir("/public/static")))) | |
// https://github.com/gorilla/mux | |
router := mux.NewRouter() | |
router.HandleFunc("/", index()) | |
router.PathPrefix("/static").Handler(http.StripPrefix("/static/", http.FileServer(pkger.Dir("/public/static")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment