-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathclonable_team_parts.go
57 lines (55 loc) · 1.53 KB
/
clonable_team_parts.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
package models
import (
"math"
"strings"
)
type ClonableTeamParts int
const (
APPS_CLONABLETEAMPARTS = 1
TABS_CLONABLETEAMPARTS = 2
SETTINGS_CLONABLETEAMPARTS = 4
CHANNELS_CLONABLETEAMPARTS = 8
MEMBERS_CLONABLETEAMPARTS = 16
)
func (i ClonableTeamParts) String() string {
var values []string
options := []string{"apps", "tabs", "settings", "channels", "members"}
for p := 0; p < 5; p++ {
mantis := ClonableTeamParts(int(math.Pow(2, float64(p))))
if i&mantis == mantis {
values = append(values, options[p])
}
}
return strings.Join(values, ",")
}
func ParseClonableTeamParts(v string) (any, error) {
var result ClonableTeamParts
values := strings.Split(v, ",")
for _, str := range values {
switch str {
case "apps":
result |= APPS_CLONABLETEAMPARTS
case "tabs":
result |= TABS_CLONABLETEAMPARTS
case "settings":
result |= SETTINGS_CLONABLETEAMPARTS
case "channels":
result |= CHANNELS_CLONABLETEAMPARTS
case "members":
result |= MEMBERS_CLONABLETEAMPARTS
default:
return nil, nil
}
}
return &result, nil
}
func SerializeClonableTeamParts(values []ClonableTeamParts) []string {
result := make([]string, len(values))
for i, v := range values {
result[i] = v.String()
}
return result
}
func (i ClonableTeamParts) isMultiValue() bool {
return true
}