-
Notifications
You must be signed in to change notification settings - Fork 1
/
htmlgetter.go
49 lines (40 loc) · 998 Bytes
/
htmlgetter.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
package jaws
import (
"fmt"
"html"
"html/template"
"sync/atomic"
)
type HtmlGetter interface {
JawsGetHtml(rq *Element) template.HTML
}
type htmlGetter struct{ v template.HTML }
func (g htmlGetter) JawsGetHtml(e *Element) template.HTML {
return g.v
}
func (g htmlGetter) JawsGetTag(rq *Request) interface{} {
return nil
}
type htmlStringGetter struct{ v StringSetter }
func (g htmlStringGetter) JawsGetHtml(e *Element) template.HTML {
return template.HTML(html.EscapeString(g.v.JawsGetString(e))) // #nosec G203
}
func (g htmlStringGetter) JawsGetTag(rq *Request) interface{} {
return g.v
}
func makeHtmlGetter(v interface{}) HtmlGetter {
switch v := v.(type) {
case HtmlGetter:
return v
case StringSetter:
return htmlStringGetter{v}
case template.HTML:
return htmlGetter{v}
case string:
h := template.HTML(v) // #nosec G203
return htmlGetter{h}
case *atomic.Value:
return atomicSetter{v}
}
panic(fmt.Errorf("expected jaws.HtmlGetter or string, not %T", v))
}