summaryrefslogtreecommitdiff
path: root/caddyconfig/httpcaddyfile
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-02-28 13:49:51 -0700
committerMatthew Holt <mholt@users.noreply.github.com>2020-02-28 13:49:51 -0700
commita60da8e7ab76a890566ce8047b92a7576a027e18 (patch)
treee191cc025a81f588e322d97870e5e1c9a3337199 /caddyconfig/httpcaddyfile
parent00e99df20952ac3e10377277d7fe13c85de4cb81 (diff)
Simplify the logic in the previous commit
Diffstat (limited to 'caddyconfig/httpcaddyfile')
-rw-r--r--caddyconfig/httpcaddyfile/directives.go20
1 files changed, 9 insertions, 11 deletions
diff --git a/caddyconfig/httpcaddyfile/directives.go b/caddyconfig/httpcaddyfile/directives.go
index c6bd24b..095e4b9 100644
--- a/caddyconfig/httpcaddyfile/directives.go
+++ b/caddyconfig/httpcaddyfile/directives.go
@@ -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]