-
Notifications
You must be signed in to change notification settings - Fork 1
/
status.go
68 lines (63 loc) · 1.24 KB
/
status.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"html/template"
"log"
"net/http"
)
func (sitest Sitest) ServeHTTP(w http.ResponseWriter, r *http.Request) {
tmplTxt := `<html>
<head>
<title>Sitest</title>
<style>
table {
width: 100%;
text-align: left;
border-collapse: collapse;
}
table td, table th {
border: 1px solid black;
padding: 2px 2px;
}
table tr:nth-child(even) {
background: #EEEEEE;
}
table thead {
border-bottom: 4px solid #333333;
}
table thead th {
font-weight: bold;
}
ul {
padding-left: 0px;
}
</style>
</head>
<body>
<p>
<h1>Sitest</h1>
<table>
<tr><th>Site</th><th>Config</th><th>Last result</th></tr>
{{ range $key, $value := .Sites }}
<tr><td>{{ $key }}</td><td>Interval: {{ $value.Config.Interval }}</td><td>{{LastResultFormated .}}</td></tr>
{{ end }}
</table>
</p>
<p class="footer">
<ul>
<li>Configuration file: {{.ConfigFile}}</li>
<li>Start time {{ .StartTime }}</li>
<li>Detailed metrics: <a href="/metrics">/metrics</a></li>
</ul>
</p>
</body>
</html>`
var funcs = template.FuncMap{"LastResultFormated": func(site *Site) Result { return site.GetLastResult() }}
tmpl, err := template.New("status-page").Funcs(funcs).Parse(tmplTxt)
if err != nil {
log.Fatal(err)
}
err = tmpl.Execute(w, sitest)
if err != nil {
log.Fatal(err)
}
}