Skip to content

Commit 9265397

Browse files
author
QM303176530
committed
casbin修改性能优化
1 parent 7aea8d7 commit 9265397

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

server/service/sys_casbin.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,22 @@ import (
2121

2222
func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error {
2323
ClearCasbin(0, authorityId)
24+
rules := [][]string{}
2425
for _, v := range casbinInfos {
2526
cm := model.CasbinModel{
2627
Ptype: "p",
2728
AuthorityId: authorityId,
2829
Path: v.Path,
2930
Method: v.Method,
3031
}
31-
addflag := AddCasbin(cm)
32-
if addflag == false {
33-
return errors.New("存在相同api,添加失败,请联系管理员")
34-
}
32+
rules = append(rules, []string{cm.AuthorityId, cm.Path, cm.Method})
3533
}
36-
return nil
37-
}
38-
39-
// @title AddCasbin
40-
// @description add casbin authority, 添加权限
41-
// @auth (2020/04/05 20:22)
42-
// @param cm model.CasbinModel
43-
// @return bool
44-
45-
func AddCasbin(cm model.CasbinModel) bool {
4634
e := Casbin()
47-
success, _ := e.AddPolicy(cm.AuthorityId, cm.Path, cm.Method)
48-
return success
35+
success, _ := e.AddPolicies(rules)
36+
if success == false {
37+
return errors.New("存在相同api,添加失败,请联系管理员")
38+
}
39+
return nil
4940
}
5041

5142
// @title UpdateCasbinApi

0 commit comments

Comments
 (0)