forked from leg100/otf
-
Notifications
You must be signed in to change notification settings - Fork 5
/
error.go
46 lines (41 loc) · 872 Bytes
/
error.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
package html
import (
"html/template"
"net/http"
)
const errorTemplateContent = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>error | otf</title>
{{ if .DevMode }}<script src="http://localhost:35729/livereload.js"></script>{{ end }}
<style>
pre {
margin: auto;
width: 60%;
max-width: 72em;
white-space: pre-wrap;
border-style: solid;
border-width: 1px;
padding: 1em;
}
</style>
</head>
<body>
<pre>{{ .Error }}</pre>
</body>
</html>
`
var errorTemplate = template.Must(template.New("error").Parse(errorTemplateContent))
func Error(w http.ResponseWriter, err string, code int, devMode bool) {
w.WriteHeader(code)
errorTemplate.Execute(w, struct { //nolint:errcheck
Error string
DevMode bool
}{
Error: err,
DevMode: devMode,
})
}