1

I have this directory structure and I'm using gorilla mux:

enter image description here

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.

Kirill
  • 11
  • 2
  • You can use `tree` to show your folder structure properly. Its hard to interpret like this. – The Fool Jan 18 '22 at 22:07
  • Also maybe describe what your problem is, I cannot tell from your question. – The Fool Jan 18 '22 at 22:09
  • Does this answer your question? [Serve static html files with gorilla mux](https://stackoverflow.com/questions/50651523/serve-static-html-files-with-gorilla-mux) – The Fool Jan 18 '22 at 22:10
  • You probably want to move the css directory under static. Edit the question to show the html pages reference the css file (specifically, show the path to the css file). – Charlie Tumahai Jan 18 '22 at 22:13
  • @TheFool when i open localhost i see only html file, without css – Kirill Jan 18 '22 at 22:27

0 Answers0