func (rm *Enforcer) DeleteUser(user string) bool {
	rm.enforcer.RemoveFilteredNamedGroupingPolicy("g2", 0, user)
	return rm.enforcer.RemoveFilteredGroupingPolicy(0, user)
}
DeleteUser deletes a user.
Returns false if the user does not exist (aka not affected).
package rbac
import (
	"fmt"
	"github.com/casbin/casbin"
	"github.com/casbin/casbin/model"
	"github.com/casbin/casbin/persist"
	casbin_rbac "github.com/casbin/casbin/rbac"
	"strings"
)
const (
	AllowAccess = "allow"
	SkipResourceId = "skip"
	permissionOwner      = 0
	permissionRole       = 1
	permissionResourceId = 2
	maxHierarchyLevel    = 3
)
type CustomFunction func(args ...interface{}) (interface{}, error)
type Enforcer struct {
	roleManager casbin_rbac.RoleManager
	enforcer    *casbin.SyncedEnforcer
}
type Context struct {
	User          string `json:"user"`
	Domain        string `json:"domain"`
	Resource      string `json:"resource"`
	ResourceId    string `json:"resourceId"`
	ResourceOwner string `json:"resourceOwner"`
	Action        string `json:"action"`
}
type Role struct {
	User                 string   `json:"user"`
	Role                 string   `json:"role"`
	Domain               string   `json:"domain"`
	Owner                string   `json:"owner"`
	RestrictedResourceId []string `json:"restrictedResourceId"`
}
type Policy struct {
	Role         string `json:"role"`
	Domain       string `json:"domain"`
	ResourceType string `json:"resourceType"`
	ResourceId   string `json:"resourceId"`
	Action       string `json:"action"`
	Effect       string `json:"effect"`
}
type Restriction struct {
	Owner string `json:"owner"`
	Role  string `json:"role"`
	UUID  string `json:"uuid"`
}
type UserPermissions struct {
	User                  string            `json:"user"`
	Domain                string            `json:"domain"`
	Permissions           []*UserPermission `json:"permissions"`
	UnmatchedRestrictions []*Restriction    `json:"unmatchedRestrictions"`
}
type UserPermission struct {
	Role     string `json:"role"`
	Domain   string `json:"domain"`
	Resource string `json:"resource"`
	UUID     string `json:"uuid"`
	Action   string `json:"action"`
	Allowed  bool   `json:"allowed"`
	Restrictions []*Restriction `json:"restrictions"`
}
func NewEnforcer(params ...interface{}) *Enforcer {
	rm := &Enforcer{}
	m := casbin.NewModel(modelText)
	if len(params) == 1 {
		switch p0 := params[0].(type) {
		case *casbin.SyncedEnforcer:
			rm.enforcer = p0
			return rm
		case persist.Adapter:
			rm.createEnforcer(m, p0)
		case model.Model:
			rm.createEnforcer(m, nil)
		default:
			panic("Unknown parameter type for Enforcer.")
		}
	} else if len(params) == 2 {
		switch p0 := params[0].(type) {
		case persist.Adapter:
			rm.createEnforcer(m, p0)
		default:
			panic("Invalid parameters for enforcer.")
		}
		switch p1 := params[1].(type) {
		case persist.Watcher:
			rm.enforcer.SetWatcher(p1)
		default:
			panic("Invalid parameters for enforcer.")
		}
	} else if len(params) == 0 {
		rm.createEnforcer(m, nil)
	} else {
		panic("Invalid parameters for enforcer.")
	}
	return rm
}
func (rm *Enforcer) createEnforcer(m model.Model, a persist.Adapter) {
	rm.enforcer = casbin.NewSyncedEnforcer()
	rm.enforcer.InitWithModelAndAdapter(m, a)
	rm.roleManager = NewRoleManager(maxHierarchyLevel)
	rm.enforcer.SetRoleManager(rm.roleManager)
	rm.enforcer.BuildRoleLinks()
	rm.enforcer.AddFunction("has_access_to_resource", rm.hasAccessToResource)
	rm.enforcer.AddFunction("matchKeys", MatchKeysFunc)
	rm.enforcer.AddFunction("bothSideMatchKeys", BothSideMatchKeysFunc)
}
func (rm *Enforcer) AddFunction(name string, function CustomFunction) {
	rm.enforcer.AddFunction(name, function)
}
func (rm *Enforcer) Enforce(pr Context) bool {
	return rm.enforcer.Enforce(pr)
}
func (rm *Enforcer) AddPolicy(p Policy) bool {
	return rm.enforcer.AddPolicy(
		p.Role,
		p.Domain,
		p.ResourceType,
		p.ResourceId,
		p.Action,
		p.Effect,
	) && rm.Save() == nil
}
func (rm *Enforcer) RemovePolicy(p Policy) bool {
	return rm.enforcer.RemovePolicy(
		p.Role,
		p.Domain,
		p.ResourceType,
		p.ResourceId,
		p.Action,
		p.Effect,
	) && rm.Save() == nil
}
func (rm *Enforcer) LinkRoles(role1, role2, domain string) bool {
	return rm.enforcer.AddGroupingPolicy(role1, role2, domain) && rm.Save() == nil
}
func (rm *Enforcer) UnlinkRoles(role1, role2, domain string) bool {
	return rm.enforcer.RemoveGroupingPolicy(role1, role2, domain) && rm.Save() == nil
}
func (rm *Enforcer) HasLink(role1, role2, domain string) bool {
	return rm.enforcer.HasGroupingPolicy(role1, role2, domain)
}
func (rm *Enforcer) AddRole(rr Role) bool {
	restrict := true
	for _, r := range rr.RestrictedResourceId {
		restrict = restrict && rm.AddRestrictionToUser(rr.User, &Restriction{rr.Owner, rr.Role, r})
	}
	addRoleG1 := rm.enforcer.AddRoleForUserInDomain(rr.User, rr.Role, rr.Domain)
	return (restrict || addRoleG1) && rm.Save() == nil
}
func (rm *Enforcer) RemoveRole(rr Role) bool {
	restrict := true
	for _, r := range rr.RestrictedResourceId {
		restrict = restrict && rm.RemoveRestrictionFromUser(rr.User, &Restriction{rr.Owner, rr.Role, r})
	}
	removeRoleG1 := rm.enforcer.DeleteRoleForUserInDomain(rr.User, rr.Role, rr.Domain)
	return (restrict || removeRoleG1) && rm.Save() == nil
}