-
Notifications
You must be signed in to change notification settings - Fork 1
/
atomicgetter.go
75 lines (63 loc) · 1.29 KB
/
atomicgetter.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
package jaws
import (
"fmt"
"html"
"html/template"
"sync/atomic"
"time"
)
type atomicGetter struct{ v *atomic.Value }
func (g atomicGetter) JawsGetBool(e *Element) (v bool) {
if x := g.v.Load(); x != nil {
v = x.(bool)
}
return
}
func (g atomicGetter) JawsSetBool(e *Element, v bool) (err error) {
g.v.Store(v)
return
}
func (g atomicGetter) JawsGetFloat(e *Element) (v float64) {
if x := g.v.Load(); x != nil {
v = x.(float64)
}
return
}
func (g atomicGetter) JawsSetFloat(e *Element, v float64) (err error) {
g.v.Store(v)
return
}
func (g atomicGetter) JawsGetString(e *Element) (v string) {
if x := g.v.Load(); x != nil {
v = x.(string)
}
return
}
func (g atomicGetter) JawsSetString(e *Element, v string) (err error) {
g.v.Store(v)
return
}
func (g atomicGetter) JawsGetTime(e *Element) (v time.Time) {
if x := g.v.Load(); x != nil {
v = x.(time.Time)
}
return
}
func (g atomicGetter) JawsSetTime(e *Element, v time.Time) (err error) {
g.v.Store(v)
return
}
func (g atomicGetter) JawsGetHtml(e *Element) template.HTML {
switch v := g.v.Load().(type) {
case nil:
return ""
case template.HTML:
return v
default:
h := template.HTML(html.EscapeString(fmt.Sprint(v))) // #nosec G203
return h
}
}
func (g atomicGetter) JawsGetTag(rq *Request) any {
return g.v
}