Let's say we have 3 endpoints. Each endpoint loads a different HTML layout and also each has its own CSS/JS files.
I was able to load static files But this always loads for all endpoints.
What I want is to load a specific static file for a specific endpoint.
func main() {
http.HandleFunc("/about", aboutHandler)
http.HandleFunc("/product", productHandler)
// *** This loads on all endpoints
fs:=http.FileServer(http.Dir("./static/")
http.Handle("/static/", http.StripPrefix("/static/",fs))
}
func aboutHandler(w http.ResponseWritter, r *http.Request) {
// *** I've tried to load it here, but shows the content of my CSS/js files instead of about.html
tpl:=template.Must(template.ParseFile("./about.html")
w.Heaer().Add("content-type", "text/html")
tpl.Execute(w, nil)
}