Directly create the files []string in the correct size for HomePage
This commit is contained in:
parent
b2a701c87a
commit
202d04f323
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user