github.com/jxgolibs/go-oauth2-server@v1.0.1/oauth/roles/roles.go (about) 1 package roles 2 3 import ( 4 "errors" 5 ) 6 7 const ( 8 // Superuser ... 9 Superuser = "superuser" 10 // User ... 11 User = "user" 12 ) 13 14 var roleWeight = map[string]int{ 15 Superuser: 100, 16 User: 1, 17 } 18 19 // IsGreaterThan returns true if role1 is greater than role2 20 func IsGreaterThan(role1, role2 string) (bool, error) { 21 // Get weight of the first role 22 weight1, ok := roleWeight[role1] 23 if !ok { 24 return false, errors.New("Role weight not found") 25 } 26 27 // Get weight of the second role 28 weight2, ok := roleWeight[role2] 29 if !ok { 30 return false, errors.New("Role weight not found") 31 } 32 33 return weight1 > weight2, nil 34 }