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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
@ -10,6 +12,9 @@ import (
|
|||||||
"lewisdale.dev/oopsie/sites"
|
"lewisdale.dev/oopsie/sites"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed templates/*
|
||||||
|
var content embed.FS
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
db := data.Connect("test.sqlite3")
|
db := data.Connect("test.sqlite3")
|
||||||
|
|
||||||
@ -31,13 +36,15 @@ func main() {
|
|||||||
http.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
|
||||||
pings := ping.ListGroupedBySite(db)
|
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.Write([]byte(err.Error()))
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
w.Write(output)
|
|
||||||
|
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