aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/dashboard/dashboard.go
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2024-10-02 17:26:41 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2024-10-02 17:27:46 -0400
commit50df0f7b61462a6bfad9e74f7c7917c6b19d4b92 (patch)
tree50f478d0cacfcb57acdc8edd0f357db304b249ae /dashboard/dashboard.go
parente8d9040688925304edad469d92518da84e1b8d96 (diff)
Add first pass at dashboard
Diffstat (limited to 'dashboard/dashboard.go')
-rw-r--r--dashboard/dashboard.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/dashboard/dashboard.go b/dashboard/dashboard.go
new file mode 100644
index 0000000..c3839f2
--- /dev/null
+++ b/dashboard/dashboard.go
@@ -0,0 +1,48 @@
+package dashboard
+
+import (
+ "html/template"
+ "log/slog"
+ "net/http"
+ "nonsense-time/api"
+ "path/filepath"
+)
+
+var Logger *slog.Logger
+var templates map[string]*template.Template
+
+func Index(w http.ResponseWriter, req *http.Request) {
+ t, ok := templates["dashboard"]
+
+ if !ok {
+ panic(t)
+ }
+
+ // TODO: poll database
+ data := struct {
+ ServerStatus api.ServerStatus
+ }{
+ ServerStatus: api.ServerStatus{},
+ }
+
+ err := t.Execute(w, data)
+ if err != nil {
+ Logger.Error("Unable to execute template", slog.Any("err", err))
+ http.Error(w, "Internal Server Error", http.StatusInternalServerError)
+ return
+ }
+}
+
+func StaticHandler(w http.ResponseWriter, req *http.Request) {
+ http.StripPrefix("/static", http.FileServer(http.Dir("static"))).ServeHTTP(w, req)
+}
+
+func init() {
+ Logger = slog.Default()
+ templates = make(map[string]*template.Template)
+ templates["dashboard"] = template.Must(template.New("base.html").ParseFiles(
+ filepath.Join("templates", "base.html"),
+ filepath.Join("templates", "dashboard", "dashboard.html"),
+ filepath.Join("templates", "dashboard", "server_status.html"),
+ ))
+}