1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-09 04:51:56 +00:00

Give read access to the current route, a feature that many of you asked for

Former-commit-id: 39295ac1331ee08d3047c84f5c8ea152bce96781
This commit is contained in:
kataras
2017-08-23 16:46:55 +03:00
parent 8b5b6b116a
commit 8b3c44b0a3
8 changed files with 129 additions and 16 deletions

View File

@@ -49,7 +49,15 @@ func (h *routerHandler) getTree(method, subdomain string) *tree {
return nil
}
func (h *routerHandler) addRoute(method, subdomain, path string, handlers context.Handlers) error {
func (h *routerHandler) addRoute(r *Route) error {
var (
routeName = r.Name
method = r.Method
subdomain = r.Subdomain
path = r.Path
handlers = r.Handlers
)
t := h.getTree(method, subdomain)
if t == nil {
@@ -58,7 +66,7 @@ func (h *routerHandler) addRoute(method, subdomain, path string, handlers contex
t = &tree{Method: method, Subdomain: subdomain, Nodes: &n}
h.trees = append(h.trees, t)
}
return t.Nodes.Add(path, handlers)
return t.Nodes.Add(routeName, path, handlers)
}
// NewDefaultHandler returns the handler which is responsible
@@ -125,7 +133,7 @@ func (h *routerHandler) Build(provider RoutesProvider) error {
// on route, it will be stacked shown in this build state
// and no in the lines of the user's action, they should read
// the docs better. Or TODO: add a link here in order to help new users.
if err := h.addRoute(r.Method, r.Subdomain, r.Path, r.Handlers); err != nil {
if err := h.addRoute(r); err != nil {
// node errors:
rp.Add("%v -> %s", err, r.String())
}
@@ -202,8 +210,9 @@ func (h *routerHandler) HandleRequest(ctx context.Context) {
continue
}
}
handlers := t.Nodes.Find(path, ctx.Params())
routeName, handlers := t.Nodes.Find(path, ctx.Params())
if len(handlers) > 0 {
ctx.SetCurrentRouteName(routeName)
ctx.Do(handlers)
// found
return