From 202d04f323c234baf2b03c0f0f5eefa4ea84a930 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Fri, 4 Oct 2024 10:11:43 +0200 Subject: [PATCH] Directly create the files []string in the correct size for HomePage --- cmd/frontend/sessions.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/frontend/sessions.go b/cmd/frontend/sessions.go index b2f94de..e546a8c 100644 --- a/cmd/frontend/sessions.go +++ b/cmd/frontend/sessions.go @@ -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) }