I have this directory structure and I'm using gorilla mux:
I trying to connect CSS-files like this:
func main() {
r := mux.NewRouter()
fileServer := http.FileServer(http.Dir("../static"))
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", fileServer))
r.HandleFunc("/", controllers.Home)
r.HandleFunc("/product", controllers.Home)
r.HandleFunc("/product/index", controllers.Home)
r.HandleFunc("/cart", controllers.Index)
r.HandleFunc("/cart/index", controllers.Index)
r.HandleFunc("/cart/buy", controllers.Buy)
r.HandleFunc("/cart/remove", controllers.Remove)
r.HandleFunc("/api/user/new", app.CreateAccount)
app.Init()
r.HandleFunc("/api/user/login", app.Authenticate)
r.Use(app.JWTAuthentication)
err := http.ListenAndServe(":8000", r)
if err != nil {
log.Fatal(err)
}
}
html
<link rel="stylesheet" type="text/css" href="../css/content.css" >
connect html file
ts, err := template.ParseFiles("../static/html/index.html")
When i open localhost i see only html file, without css.
If i use standard http router, then this works correctly.