/
registry.go
56 lines (47 loc) · 1.01 KB
/
registry.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
package types
import (
"reflect"
"sync"
)
// Registry for Any
func NewTypesRegistry() *TypesRegistry {
return &TypesRegistry{
registry: make(map[string]reflect.Type),
}
}
type TypesRegistry struct {
registry map[string]reflect.Type
sync.RWMutex
}
func (this *TypesRegistry) Get(name string) (reflect.Type, bool) {
this.RLock()
defer this.RUnlock()
t, ok := this.registry[name]
return t, ok
}
func (this *TypesRegistry) Register(name string, t reflect.Type) {
this.Lock()
this.registry[name] = t
this.Unlock()
}
// Registry for Perms bitmaps
func NewPermsRegistry() *PermsRegistry {
return &PermsRegistry{
registry: make(map[string]*PermissionsBitmap),
}
}
type PermsRegistry struct {
registry map[string]*PermissionsBitmap
sync.RWMutex
}
func (p *PermsRegistry) Get(name string) (*PermissionsBitmap, bool) {
p.RLock()
defer p.RUnlock()
r, ok := p.registry[name]
return r, ok
}
func (p *PermsRegistry) Register(name string, bmap *PermissionsBitmap) {
p.Lock()
p.registry[name] = bmap
p.Unlock()
}