refactor: use go:embed for templates
Templates are now embedded using //go:embed and parsed once at startup with template.Must(template.ParseFS(...)). This avoids re-parsing template files from disk on every request and removes the dependency on template files being present at runtime. closes #7
This commit is contained in:
@@ -21,7 +21,7 @@ func (h *Handlers) HandleLoginPage() http.HandlerFunc {
|
||||
"Error": "",
|
||||
}
|
||||
|
||||
h.renderTemplate(w, r, []string{"templates/base.html", "templates/login.html"}, data)
|
||||
h.renderTemplate(w, r, "login.html", data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func (h *Handlers) HandleLoginSubmit() http.HandlerFunc {
|
||||
"Error": "Username and password are required",
|
||||
}
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
h.renderTemplate(w, r, []string{"templates/base.html", "templates/login.html"}, data)
|
||||
h.renderTemplate(w, r, "login.html", data)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ func (h *Handlers) HandleLoginSubmit() http.HandlerFunc {
|
||||
"Error": "Invalid username or password",
|
||||
}
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
h.renderTemplate(w, r, []string{"templates/base.html", "templates/login.html"}, data)
|
||||
h.renderTemplate(w, r, "login.html", data)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func (h *Handlers) HandleLoginSubmit() http.HandlerFunc {
|
||||
"Error": "Invalid username or password",
|
||||
}
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
h.renderTemplate(w, r, []string{"templates/base.html", "templates/login.html"}, data)
|
||||
h.renderTemplate(w, r, "login.html", data)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user