Simplify the logic in the previous commit

This commit is contained in:
Matthew Holt 2020-02-28 13:49:51 -07:00
parent 00e99df209
commit a60da8e7ab
No known key found for this signature in database
GPG Key ID: 2A349DD577D586A5
1 changed files with 9 additions and 11 deletions

View File

@ -298,18 +298,16 @@ func sortRoutes(routes []ConfigValue) {
jPM = pathMatcher
}
// if there is only one path in the matcher, sort by
// longer path (more specific) first; if one of the
// routes doesn't have a matcher, then it's treated
// like a zero-length path matcher
switch {
case iPM == nil && jPM != nil:
return false
case iPM != nil && jPM == nil:
return true
case iPM != nil && jPM != nil:
return len(iPM[0]) > len(jPM[0])
// sort by longer path (more specific) first; missing
// path matchers are treated as zero-length paths
var iPathLen, jPathLen int
if iPM != nil {
iPathLen = len(iPM[0])
}
if jPM != nil {
jPathLen = len(jPM[0])
}
return iPathLen > jPathLen
}
return dirPositions[iDir] < dirPositions[jDir]