MCPcopy
hub / github.com/apache/casbin / SortPoliciesByPriority

Method SortPoliciesByPriority

model/model.go:321–344  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

319}
320
321func (model Model) SortPoliciesByPriority() error {
322 for ptype, assertion := range model["p"] {
323 priorityIndex, err := model.GetFieldIndex(ptype, constant.PriorityIndex)
324 if err != nil {
325 continue
326 }
327 policies := assertion.Policy
328 sort.SliceStable(policies, func(i, j int) bool {
329 p1, err := strconv.Atoi(policies[i][priorityIndex])
330 if err != nil {
331 return true
332 }
333 p2, err := strconv.Atoi(policies[j][priorityIndex])
334 if err != nil {
335 return true
336 }
337 return p1 < p2
338 })
339 for i, policy := range assertion.Policy {
340 assertion.PolicyMap[strings.Join(policy, ",")] = i
341 }
342 }
343 return nil
344}
345
346var (
347 pPattern = regexp.MustCompile("^p_")

Callers 4

loadFilteredPolicyCtxMethod · 0.80
loadPolicyFromAdapterMethod · 0.80
loadFilteredPolicyMethod · 0.80

Calls 1

GetFieldIndexMethod · 0.95

Tested by

no test coverage detected