mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-15 21:04:56 +00:00
fix(policy/checker): more explicit short-circuit
Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
@@ -20,8 +20,6 @@ type List []Impl
|
|||||||
// It returns true only if *all* checkers return true (AND semantics).
|
// It returns true only if *all* checkers return true (AND semantics).
|
||||||
// If any checker returns an error, the function returns false and the error.
|
// If any checker returns an error, the function returns false and the error.
|
||||||
func (l List) Check(r *http.Request) (bool, error) {
|
func (l List) Check(r *http.Request) (bool, error) {
|
||||||
// Assume success until a checker says otherwise.
|
|
||||||
allOk := true
|
|
||||||
for _, c := range l {
|
for _, c := range l {
|
||||||
ok, err := c.Check(r)
|
ok, err := c.Check(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -31,11 +29,11 @@ func (l List) Check(r *http.Request) (bool, error) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
// One false means the combined result is false. Short-circuit
|
// One false means the combined result is false. Short-circuit
|
||||||
// so we don't waste time.
|
// so we don't waste time.
|
||||||
allOk = false
|
return false, err
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return allOk, nil
|
// Assume success until a checker says otherwise.
|
||||||
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l List) Hash() string {
|
func (l List) Hash() string {
|
||||||
|
|||||||
Reference in New Issue
Block a user