- 开始添加casbin做角色,权限管理

This commit is contained in:
gazebo
2019-08-06 11:26:08 +08:00
parent 407844aa81
commit 438879ac4f
11 changed files with 427 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package authz
import (
"strings"
"git.rosy.net.cn/baseapi/utils"
)
const (
RoleNameSep = "/"
RolePrefix = "role"
StoreRolePrefix = "store"
)
func GenStoreRoleName(storeID int) (roleName string) {
return strings.Join([]string{
RolePrefix,
StoreRolePrefix,
utils.Int2Str(storeID),
}, RoleNameSep)
}
func GetStoreIDFromRole(roleName string) (storeID int) {
list := strings.Split(roleName, RoleNameSep)
if len(list) == 3 {
storeID = int(utils.Str2Int64WithDefault(list[2], 0))
}
return storeID
}