/
http.go
45 lines (36 loc) · 1.05 KB
/
http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
//go:generate go-bindata display.html
import (
"encoding/json"
"net/http"
"github.com/flosch/pongo2"
log "github.com/sirupsen/logrus"
)
func htmlHandler(res http.ResponseWriter, r *http.Request) {
tplsrc := MustAsset("display.html")
template, err := pongo2.FromString(string(tplsrc))
if err != nil {
log.Fatal(err)
}
if err := template.ExecuteWriter(pongo2.Context{
"results": probeMonitors,
"certificateOK": certificateOK,
"certificateExpiresSoon": certificateExpiresSoon,
"version": version,
}, res); err != nil {
log.WithError(err).Error("Unable to render display template")
}
}
func httpStatusHandler(res http.ResponseWriter, r *http.Request) {
httpStatus := http.StatusOK
for _, mon := range probeMonitors {
if mon.Status != certificateOK {
httpStatus = http.StatusInternalServerError
}
}
res.WriteHeader(httpStatus)
}
func jsonHandler(res http.ResponseWriter, r *http.Request) {
res.Header().Set("Content-Type", "application/json")
json.NewEncoder(res).Encode(probeMonitors)
}