-
Notifications
You must be signed in to change notification settings - Fork 1
/
atomicsetter.go
75 lines (63 loc) · 1.29 KB
/
atomicsetter.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 atomicSetter struct{ v *atomic.Value }
func (g atomicSetter) JawsGetBool(e *Element) (v bool) {
if x := g.v.Load(); x != nil {
v = x.(bool)
}
return
}
func (g atomicSetter) JawsSetBool(e *Element, v bool) (err error) {
g.v.Store(v)
return
}
func (g atomicSetter) JawsGetFloat(e *Element) (v float64) {
if x := g.v.Load(); x != nil {
v = x.(float64)
}
return
}
func (g atomicSetter) JawsSetFloat(e *Element, v float64) (err error) {
g.v.Store(v)
return
}
func (g atomicSetter) JawsGetString(e *Element) (v string) {
if x := g.v.Load(); x != nil {
v = x.(string)
}
return
}
func (g atomicSetter) JawsSetString(e *Element, v string) (err error) {
g.v.Store(v)
return
}
func (g atomicSetter) JawsGetTime(e *Element) (v time.Time) {
if x := g.v.Load(); x != nil {
v = x.(time.Time)
}
return
}
func (g atomicSetter) JawsSetTime(e *Element, v time.Time) (err error) {
g.v.Store(v)
return
}
func (g atomicSetter) 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 atomicSetter) JawsGetTag(rq *Request) any {
return g.v
}