Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Last active January 1, 2021 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xeoncross/6a48c341ab0c8a44a67b0ed0e54b9ac3 to your computer and use it in GitHub Desktop.
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
// 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