-
Notifications
You must be signed in to change notification settings - Fork 48
/
role.go
53 lines (43 loc) · 1.09 KB
/
role.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
package domain
type (
// PermissionSet is a list of permissions
PermissionSet interface {
Permissions() []string
}
// Role is an interface for available role
Role interface {
Label() string
PermissionSet
}
// StringRole is simple representation of Role interface
StringRole string
complexRole struct {
label string
permissions []string
}
)
// NewRole creates instance of Role interface
func NewRole(label string, permissions []string) Role {
return complexRole{
label: label,
permissions: permissions,
}
}
// PermissionAuthorized is the default permission for authorized users
var PermissionAuthorized = string("PermissionAuthorized")
// Label returns the role's label
func (r StringRole) Label() string {
return string(r)
}
// Permissions returns the list of role's permissions
func (r StringRole) Permissions() []string {
return []string{string(r)}
}
// Label returns the role's label
func (r complexRole) Label() string {
return r.label
}
// Permissions returns the list of role's permissions
func (r complexRole) Permissions() []string {
return r.permissions
}