-
Notifications
You must be signed in to change notification settings - Fork 1
/
string.go
45 lines (37 loc) · 799 Bytes
/
string.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
package jaws
import (
"html"
"html/template"
"sync"
)
// String wraps a mutex and a string, and implements jaws.StringSetter and jaws.HtmlGetter.
// String.JawsGetHtml() will escape the string before returning it.
type String struct {
mu sync.Mutex
Value string
}
func (s *String) Set(val string) {
s.mu.Lock()
s.Value = val
s.mu.Unlock()
}
func (s *String) Get() (val string) {
s.mu.Lock()
val = s.Value
s.mu.Unlock()
return
}
func (s *String) String() string {
return s.Get()
}
func (s *String) JawsGetHtml(*Element) (val template.HTML) {
val = template.HTML(html.EscapeString(s.Get())) // #nosec G203
return
}
func (s *String) JawsGetString(*Element) string {
return s.String()
}
func (s *String) JawsSetString(e *Element, val string) error {
s.Set(val)
return nil
}