AddNamedPolicy adds an authorization rule to the current named policy. If the rule already exists, the function returns false and the rule will not be added. Otherwise the function returns true by adding the new rule.
(ptype string, params ...interface{})
| 255 | // If the rule already exists, the function returns false and the rule will not be added. |
| 256 | // Otherwise the function returns true by adding the new rule. |
| 257 | func (e *Enforcer) AddNamedPolicy(ptype string, params ...interface{}) (bool, error) { |
| 258 | if strSlice, ok := params[0].([]string); len(params) == 1 && ok { |
| 259 | strSlice = append(make([]string, 0, len(strSlice)), strSlice...) |
| 260 | return e.addPolicy("p", ptype, strSlice) |
| 261 | } |
| 262 | policy := make([]string, 0) |
| 263 | for _, param := range params { |
| 264 | policy = append(policy, param.(string)) |
| 265 | } |
| 266 | |
| 267 | return e.addPolicy("p", ptype, policy) |
| 268 | } |
| 269 | |
| 270 | // AddNamedPolicies adds authorization rules to the current named policy. |
| 271 | // If the rule already exists, the function returns false for the corresponding rule and the rule will not be added. |