-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
47 lines (41 loc) · 933 Bytes
/
utils.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
package perman
func (p Perman) Keys() []string {
keys := make([]string, 0)
for key := range p.flags {
keys = append(keys, key)
}
return keys
}
func (p Perman) Values() []int64 {
values := make([]int64, 0)
for flag := range p.flags {
values = append(values, p.flags[flag])
}
return values
}
func (p Perman) Get(flag string) int64 {
value, ok := p.flags[flag]
if ok {
return value
} else {
return int64(0)
}
}
func (p Perman) Add(permission int64, key string) int64 {
oldValues := p.Deserialize(permission)
newValues := append(oldValues, key)
return p.Serialize(newValues)
}
func (p Perman) Remove(permission int64, key string) int64 {
oldValues := p.Deserialize(permission)
newValues := make([]string, 0)
for _, value := range oldValues {
if value != key {
newValues = append(newValues, value)
}
}
return p.Serialize(newValues)
}
func (p Perman) Full() int64 {
return p.Serialize(p.Keys())
}