I have two html files that are parsed as follows:
var LoginTemplate = template.Must(template.ParseFiles(
"views/_base.html",
"views/login.html",
))
And executed as such:
func LoginFormHandler(w http.ResponseWriter, r *http.Request, ctx *models.Context) error {
err := LoginTemplate.Execute(w, ctx)
if err != nil {
http.Error(w, err.Error(), 404)
}
return nil
}
Here are the contents of _base.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<title>{{ template "title" . }}</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{ template "styles" . }}
{{ template "scripts" . }}
</head>
{{ template "content" . }}
</html>
The templates specified above are all defined in login.html. For example, "styles" wraps all of my CSS links, etc. In my main function, I use a gorilla/pat router to handle several page requests to the server. Additionally, I want to serve my static assets folders like this:
router.PathPrefix("/assets/").Handler(http.StripPrefix("/assets/", http.FileServer(http.Dir("./assets/"))))
if err := http.ListenAndServe(":"+settings.Server.Port, router); err != nil {
panic(err)
}
However, upon building and running my program, then navigating to local host, I see that none of the CSS or js appears to be rendering. My css and js folders are in this tree:
ROOT/
assets/
css/
js/