Initial commit

This commit is contained in:
David J. Allen 2024-02-21 15:56:34 -07:00
commit c04107cf3d
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC
6 changed files with 131 additions and 0 deletions

28
handler.go Normal file
View file

@ -0,0 +1,28 @@
package main
import (
"encoding/json"
"html/template"
"net/http"
)
func (app *App) dashboardHandler() http.HandlerFunc {
return func(writer http.ResponseWriter, request *http.Request) {
tmpl, err := template.New("index.html").ParseFiles("index.html")
if err != nil {
http.Error(writer, err.Error(), http.StatusInternalServerError)
return
}
session, err := json.Marshal(getSession(request.Context()))
if err != nil {
http.Error(writer, err.Error(), http.StatusInternalServerError)
return
}
err = tmpl.ExecuteTemplate(writer, "index.html", string(session))
if err != nil {
http.Error(writer, err.Error(), http.StatusInternalServerError)
return
}
}
}