1
0
mirror of https://github.com/kataras/iris.git synced 2026-02-06 18:55:57 +00:00

Update to 8.0.2. Read HISTORY.md for the surpise

Former-commit-id: bbdf020ccaa986c332716aa7f749b7bdc24e427e
This commit is contained in:
kataras
2017-07-15 17:40:29 +03:00
parent 5015d92ece
commit 5752625c80
12 changed files with 508 additions and 31 deletions

View File

@@ -53,7 +53,7 @@ func (h *routerHandler) addRoute(method, subdomain, path string, handlers contex
t := h.getTree(method, subdomain)
if t == nil {
n := make(node.Nodes, 0)
n := node.Nodes{}
// first time we register a route to this method with this subdomain
t = &tree{Method: method, Subdomain: subdomain, Nodes: &n}
h.trees = append(h.trees, t)
@@ -81,7 +81,34 @@ func (h *routerHandler) Build(provider RoutesProvider) error {
// sort, subdomains goes first.
sort.Slice(registeredRoutes, func(i, j int) bool {
return len(registeredRoutes[i].Subdomain) >= len(registeredRoutes[j].Subdomain)
first, second := registeredRoutes[i], registeredRoutes[j]
lsub1 := len(first.Subdomain)
lsub2 := len(second.Subdomain)
firstSlashLen := strings.Count(first.Path, "/")
secondSlashLen := strings.Count(second.Path, "/")
if lsub1 == lsub2 && first.Method == second.Method {
if secondSlashLen < firstSlashLen {
// fixes order when wildcard root is registered before other wildcard paths
return true
}
if secondSlashLen == firstSlashLen {
// fixes order when static path with the same prefix with a wildcard path
// is registered after the wildcard path, although this is managed
// by the low-level node but it couldn't work if we registered a root level wildcard, this fixes it.
if len(first.Tmpl().Params) == 0 {
return false
}
if len(second.Tmpl().Params) == 0 {
return true
}
}
}
// the rest are handled inside the node
return lsub1 > lsub2
})
rp := errors.NewReporter()