mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 18:07:01 +00:00
new feature: handle different param types in the exact same path pattern
implements https://github.com/kataras/iris/issues/1315 Former-commit-id: 3e9276f2a95d6fc7c10fbf91186d041dcba72611
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/core/errors"
|
||||
"github.com/kataras/iris/macro"
|
||||
macroHandler "github.com/kataras/iris/macro/handler"
|
||||
)
|
||||
|
||||
// MethodNone is a Virtual method
|
||||
@@ -109,6 +110,20 @@ func (repo *repository) get(routeName string) *Route {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repo *repository) getRelative(r *Route) *Route {
|
||||
if r.tmpl.IsTrailing() || !macroHandler.CanMakeHandler(r.tmpl) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, route := range repo.routes {
|
||||
if r.Subdomain == route.Subdomain && r.Method == route.Method && r.FormattedPath == route.FormattedPath && !route.tmpl.IsTrailing() {
|
||||
return route
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repo *repository) getByPath(tmplPath string) *Route {
|
||||
if repo.pos != nil {
|
||||
if idx, ok := repo.pos[tmplPath]; ok {
|
||||
@@ -345,6 +360,8 @@ func (api *APIBuilder) Handle(method string, relativePath string, handlers ...co
|
||||
var route *Route // the last one is returned.
|
||||
for _, route = range routes {
|
||||
// global
|
||||
|
||||
route.topLink = api.routes.getRelative(route)
|
||||
api.routes.register(route)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user