-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta.go
132 lines (115 loc) · 2.27 KB
/
meta.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package sola
import (
"errors"
"html/template"
"io"
)
const (
// Version of Sola
Version = "v2.1.2"
// Issuer of InternalError
Issuer = "sola"
)
// error(s)
var (
ErrM2H = errors.New("Middleware using next() can't be Handler")
errM2H = IError(Issuer, ErrM2H)
)
// ContextKey
const (
CtxSola = "sola"
CtxRequest = "sola.request"
CtxResponse = "sola.response"
)
// TplInternalError for sola
var TplInternalError = template.Must(template.
New("SolaInternalError").
Parse(`<html>
<head>
<meta charset="utf-8">
<title>Sola Internal Error</title>
<style>
body {
margin-top: 50px;
}
th {
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
border-top: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: left;
padding: 6px 6px 6px 12px;
}
th.top {
border-left: 1px solid #C1DAD7;
border-right: 1px solid #C1DAD7;
}
th.spec {
border-left: 1px solid #C1DAD7;
border-top: 0;
color: #797268;
}
td {
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
font-size: 11px;
padding: 6px 6px 6px 12px;
color: #4f6b72;
}
tr:nth-child(odd) td {
background: #F5FAFA;
color: #797268;
}
</style>
</head>
<body>
<h1 style="text-align: center;">Sola Internal Error</h1>
<table cellspacing="0" style="width: 70%;margin: auto;">
<tr>
<th class="top">Meta</th>
<th>Value</th>
</tr>
{{range $i,$e := .}}
<tr>
<th class="spec">{{$i}}</td>
<td>{{$e}}</td>
</tr>
{{end}}
</table>
</body>
</html>`))
// InternalError of sola
type InternalError struct {
error
issuer string
}
// IError Internal Error
func IError(issuer string, e error) *InternalError {
return &InternalError{e, issuer}
}
// Error Internal
func Error(issuer string, e error) error {
return IError(issuer, e)
}
// Issuer of InternalError
func (e *InternalError) Issuer() string {
return e.issuer
}
// Handler of InternalError
func (e *InternalError) Handler() Handler {
return func(c Context) error {
return e
}
}
// Write to io.Writer
func (e *InternalError) Write(w io.Writer) error {
errStr := e.error.Error()
return TplInternalError.Execute(w, map[string]string{
"Sola Version": Version,
"Issuer": e.Issuer(),
"Error": errStr,
})
}