You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"github.com/casbin/casbin/v2"
"github.com/casbin/casbin/v2/model"
fileAdapter "github.com/casbin/casbin/v2/persist/file-adapter"
"github.com/casbin/casbin/v2/util"
"log"
)
func main() {
m, _ := model.NewModelFromFile("model5.conf")
a := fileAdapter.NewAdapter("policy5.csv")
e, _ := casbin.NewEnforcer(m, a)
g := e.GetNamedGroupingPolicy("g")
for _, gp := range g {
e.AddNamedDomainLinkConditionFunc("g", gp[0], gp[1], gp[2], util.TimeMatchFunc)
}
check5(e, []interface{}{"alice", "domain1", "service1", "/add"})
check5(e, []interface{}{"alice", "domain1", "service1", "/list"})
check5(e, []interface{}{"alice", "domain1", "service1", "/userEdit"})
check5(e, []interface{}{"alice", "domain1", "service1", "/get/9527/info"})
log.Println("-------")
/**
here, the error will occer
*/
rolesForUserInDomain := e.GetRolesForUserInDomain("alice", "domain1")
for i := range rolesForUserInDomain {
role := rolesForUserInDomain[i]
permissionsForUser := e.GetPermissionsForUser(role)
for j := range permissionsForUser {
log.Println(permissionsForUser[j])
}
}
log.Println("--------------")
}
func check5(e *casbin.Enforcer, slice1 []interface{}) {
result1, error := e.Enforce(slice1...)
if error != nil {
log.Println(error)
}
log.Println(result1)
}
Your request(s):
I want to use GetRolesForUserInDomain to obtain roles that the user have, but a error occurred.
I found that if I not use this method AddNamedDomainLinkConditionFunc, there is no problem.
I want to know how to solve this? think you!
The text was updated successfully, but these errors were encountered:
What's your scenario? What do you want to achieve?
I want to use GetRolesForUserInDomain to obtain roles that the user have
Your model:
Your policy:
codes:
Your request(s):
The text was updated successfully, but these errors were encountered: