From 27f6d749d37ed94da0a6a61200598f0aea898b4d Mon Sep 17 00:00:00 2001 From: Lewis Dale Date: Tue, 14 May 2024 12:52:36 +0100 Subject: [PATCH] Start outputting HTML --- main.go | 13 ++++++++++--- templates/index.html | 9 +++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 templates/index.html diff --git a/main.go b/main.go index a0389d2..63903a0 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,9 @@ package main import ( + "embed" "encoding/json" + "html/template" "net/http" _ "github.com/mattn/go-sqlite3" @@ -10,6 +12,9 @@ import ( "lewisdale.dev/oopsie/sites" ) +//go:embed templates/* +var content embed.FS + func main() { db := data.Connect("test.sqlite3") @@ -31,13 +36,15 @@ func main() { http.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) { pings := ping.ListGroupedBySite(db) - if output, err := json.Marshal(pings); err != nil { + if _, err := json.Marshal(pings); err != nil { w.Write([]byte(err.Error())) w.WriteHeader(http.StatusInternalServerError) return } else { - w.Header().Set("Content-Type", "application/json") - w.Write(output) + w.Header().Set("Content-Type", "text/html") + + t, _ := template.ParseFS(content, "templates/index.html") + t.Execute(w, nil) } }) diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..fdaa5de --- /dev/null +++ b/templates/index.html @@ -0,0 +1,9 @@ + + + + Oopsie + + +

Oopsie uptime monitoring

+ + \ No newline at end of file