Directly create the files []string in the correct size for HomePage

This commit is contained in:
Jason Streifling 2024-10-04 10:11:43 +02:00
parent b2a701c87a
commit 202d04f323

View File

@ -54,19 +54,20 @@ func HomePage(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
log.Fatalln(err)
}
files := []string{c.WebDir + "/templates/index.html"}
files := make([]string, 2)
files[0] = c.WebDir + "/templates/index.html"
if numRows == 0 {
files = append(files, c.WebDir+"/templates/first-user.html")
files[1] = c.WebDir + "/templates/first-user.html"
tmpl, err := template.ParseFiles(files...)
template.Must(tmpl, err).Execute(w, nil)
} else {
session, _ := s.Get(r, "cookie")
if auth, ok := session.Values["authenticated"].(bool); auth && ok {
files = append(files, c.WebDir+"/templates/hub.html")
files[1] = c.WebDir + "/templates/hub.html"
tmpl, err := template.ParseFiles(files...)
template.Must(tmpl, err).Execute(w, session.Values["role"])
} else {
files = append(files, c.WebDir+"/templates/login.html")
files[1] = c.WebDir + "/templates/login.html"
tmpl, err := template.ParseFiles(files...)
template.Must(tmpl, err).Execute(w, nil)
}