-
Notifications
You must be signed in to change notification settings - Fork 35
/
global.go
51 lines (40 loc) · 1.17 KB
/
global.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
package roles
import "net/http"
// Global global role instance
var Global = &Role{}
// Register register role with conditions
func Register(name string, fc Checker) {
Global.Register(name, fc)
}
// Allow allows permission mode for roles
func Allow(mode PermissionMode, roles ...string) *Permission {
return Global.Allow(mode, roles...)
}
// Deny deny permission mode for roles
func Deny(mode PermissionMode, roles ...string) *Permission {
return Global.Deny(mode, roles...)
}
// Get role defination
func Get(name string) (Checker, bool) {
return Global.Get(name)
}
// Remove role definition from global role instance
func Remove(name string) {
Global.Remove(name)
}
// Reset role definitions from global role instance
func Reset() {
Global.Reset()
}
// MatchedRoles return defined roles from user
func MatchedRoles(req *http.Request, user interface{}) []string {
return Global.MatchedRoles(req, user)
}
// HasRole check if current user has role
func HasRole(req *http.Request, user interface{}, roles ...string) bool {
return Global.HasRole(req, user)
}
// NewPermission initialize a new permission for default role
func NewPermission() *Permission {
return Global.NewPermission()
}