This commit is contained in:
1 parent
a7a55b6a90
commit
27f6d749d3
2 files changed
+19
-3
No files matched your search
@@ -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)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Oopsie</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Oopsie uptime monitoring</h1>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user