I'm working on my first go web app and trying to embed files using https://github.com/elazarl/go-bindata-assetfs
This is my project structure:
project_dir
├───common
├───routers
└───templates
├───images
└───css
generated a source file:
go-bindata-assetfs -pkg common -prefix "templates/" templates/css/ templates/ templates/images/
now I have the old routes to static files:
package routers
import (
"net/http"
"github.com/gorilla/mux"
)
func SetTemplatesRoutes(router *mux.Router) *mux.Router {
fs := http.FileServer(http.Dir("templates"))
router.Handle("/templates/", fs)
router.PathPrefix("/css/").Handler(
http.StripPrefix("/css/",
http.FileServer(http.Dir("templates/css")),
))
router.PathPrefix("/dist/").Handler(
http.StripPrefix("/dist/",
http.FileServer(http.Dir("templates/dist")),
))
router.PathPrefix("/images/").Handler(
http.StripPrefix("/images/",
http.FileServer(http.Dir("templates/images")),
))
return router
}
that I'd like replace with the embedded files just to make the html templates bind the css and image files. This is my attempt:
fs := http.FileServer(
&assetfs.AssetFS{Asset: common.Asset, AssetDir: common.AssetDir, AssetInfo: common.AssetInfo})
//
router.Handle("/", fs)
router.PathPrefix("/css/").Handler(
http.StripPrefix("/css/",
fs,
))
router.PathPrefix("/dist/").Handler(
http.StripPrefix("/dist/",
fs,
))
router.PathPrefix("/images/").Handler(
http.StripPrefix("/images/",
fs,
))
that doesn't work.
Any suggestion to solve it?