package web import ( "bytes" "html/template" "net/http" ) func index(w http.ResponseWriter, r *http.Request) { // Serve static files if r.URL.Path != "/" { fileServer.ServeHTTP(w, r) return } page := struct { Title string Content template.HTML }{} var contentBuffer bytes.Buffer sCookie, err := r.Cookie("session") if err == nil && isAuthenticated(sCookie.Value) == nil { page.Title = "Miniwol" contentBuffer.WriteString("Device") } else { page.Title = "Login" err = loginTemplate.Execute(&contentBuffer, struct{}{}) if err != nil { panic(err) } } page.Content = template.HTML(contentBuffer.String()) err = pageTemplate.Execute(w, page) if err != nil { panic(err) } }