-
Notifications
You must be signed in to change notification settings - Fork 0
/
attribute.go
executable file
·50 lines (41 loc) · 1.01 KB
/
attribute.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
package gweb
import "sync"
type AttributesKey string
func (ak AttributesKey) String() string {
return string(ak)
}
type Attributes struct {
_map sync.Map
}
func (att *Attributes) Put(key AttributesKey, value interface{}) {
//att.Lock()
//att.Map[key] = value
att._map.Store(key, value)
//defer att.Unlock()
}
func (att *Attributes) GetOrPut(key AttributesKey, value interface{}) (actual interface{}, loaded bool) {
//att.Lock()
//att.Map[key] = value
return att._map.LoadOrStore(key, value)
//defer att.Unlock()
}
func (att *Attributes) GetMap() map[string]interface{} {
data := make(map[string]interface{})
att._map.Range(func(key, value interface{}) bool {
data[key.(AttributesKey).String()] = value
return true
})
return data
}
func (att *Attributes) Get(key AttributesKey) interface{} {
//att.RLock()
//defer att.RUnlock()
v, _ := att._map.Load(key)
return v
}
func (att *Attributes) Delete(key AttributesKey) {
//att.RLock()
//defer att.RUnlock()
//delete(att.Map, key)
att._map.Delete(key)
}