So I am trying to get CSS
working using my Go
server, but the css file is not loading correcly, I get 404 file not found
. It works fine when I run Index.html
straight from the browser.
My directory structure with #
representing a folder and -
a file:
- Main.go
# static
- index.html
# css
- Styles.css
Index.html
contains:
<link rel="stylesheet" type="text/css" href="css/Styles.css"/>
These are all my handlers:
muxRouter := mux.NewRouter()
muxRouter.HandleFunc("/", basicHandler)
muxRouter.HandleFunc("/ws", wsHandler)
muxRouter.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("static/css"))))
basicHandler contains:
toSend := template.HTMLEscapeString(outputMessage)
toSend = strings.Replace(toSend, "
", "<br>", -1)
templateError := allTemplates.ExecuteTemplate(responseWriter, "index.html", template.HTML(toSend))
if templateError != nil {
log.Fatal("Template error: ", templateError)
}
wsHandler handles the websocket which my program uses.