generated from TrueCloudLab/basic
[#86] engine: Simplify multiple chains processing
All checks were successful
DCO action / DCO (pull_request) Successful in 43s
Tests and linters / Tests (1.21) (pull_request) Successful in 50s
Tests and linters / Tests (1.20) (pull_request) Successful in 55s
Tests and linters / Tests with -race (pull_request) Successful in 1m9s
Tests and linters / Staticcheck (pull_request) Successful in 1m38s
Tests and linters / Lint (pull_request) Successful in 1m46s
All checks were successful
DCO action / DCO (pull_request) Successful in 43s
Tests and linters / Tests (1.21) (pull_request) Successful in 50s
Tests and linters / Tests (1.20) (pull_request) Successful in 55s
Tests and linters / Tests with -race (pull_request) Successful in 1m9s
Tests and linters / Staticcheck (pull_request) Successful in 1m38s
Tests and linters / Lint (pull_request) Successful in 1m46s
So, it's sunday evening and I am sitting on-call trying to debug strange node behaviour. It took me 3 whole minutes to understand the code being changed: it accumulates bools in slices, even though no slice is needed; it uses subtle condition from the first loop to make decision in the second one, and finally it uses named return values. In this commit we remove the slice and the second loop, because why not. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
96225afacb
commit
a11e80e2c7
1 changed files with 9 additions and 14 deletions
|
@ -42,41 +42,36 @@ func (dr *defaultChainRouter) checkLocal(name chain.Name, rt RequestTarget, r re
|
|||
if dr.local == nil {
|
||||
return
|
||||
}
|
||||
var ruleFounds []bool
|
||||
|
||||
var hasAllow bool
|
||||
for _, target := range rt.Targets() {
|
||||
status, ruleFound, err = dr.matchLocalOverrides(name, target, r)
|
||||
if err != nil || ruleFound && status != chain.Allow {
|
||||
return
|
||||
}
|
||||
ruleFounds = append(ruleFounds, ruleFound)
|
||||
hasAllow = hasAllow || ruleFound
|
||||
}
|
||||
|
||||
status = chain.NoRuleFound
|
||||
for _, ruleFound = range ruleFounds {
|
||||
if ruleFound {
|
||||
status = chain.Allow
|
||||
break
|
||||
}
|
||||
if hasAllow {
|
||||
status = chain.Allow
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (dr *defaultChainRouter) checkMorph(name chain.Name, rt RequestTarget, r resource.Request) (status chain.Status, ruleFound bool, err error) {
|
||||
var ruleFounds []bool
|
||||
var hasAllow bool
|
||||
for _, target := range rt.Targets() {
|
||||
status, ruleFound, err = dr.matchMorphRuleChains(name, target, r)
|
||||
if err != nil || ruleFound && status != chain.Allow {
|
||||
return
|
||||
}
|
||||
ruleFounds = append(ruleFounds, ruleFound)
|
||||
hasAllow = hasAllow || ruleFound
|
||||
}
|
||||
|
||||
status = chain.NoRuleFound
|
||||
for _, ruleFound = range ruleFounds {
|
||||
if ruleFound {
|
||||
status = chain.Allow
|
||||
break
|
||||
}
|
||||
if hasAllow {
|
||||
status = chain.Allow
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue