Start outputting HTML
All checks were successful
Build and copy to prod / build-and-copy (push) Successful in 36s
All checks were successful
Build and copy to prod / build-and-copy (push) Successful in 36s
This commit is contained in:
parent
a7a55b6a90
commit
27f6d749d3
13
main.go
13
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)
|
||||
}
|
||||
})
|
||||
|
||||
|
9
templates/index.html
Normal file
9
templates/index.html
Normal file
@ -0,0 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Oopsie</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Oopsie uptime monitoring</h1>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user