From 39cff3481ca9e2726231c3067f58fcf3a8c9e333 Mon Sep 17 00:00:00 2001 From: Orne Brocaar Date: Wed, 5 Aug 2015 09:26:50 +0200 Subject: [PATCH 1/2] Add note about the availability of CurrentRoute. --- mux.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mux.go b/mux.go index e253230..4a94a23 100644 --- a/mux.go +++ b/mux.go @@ -312,6 +312,9 @@ func Vars(r *http.Request) map[string]string { } // CurrentRoute returns the matched route for the current request, if any. +// Note: this only works when called inside the handler of the matched route +// because it uses context.Get() which will be cleared after executing the +// handler. func CurrentRoute(r *http.Request) *Route { if rv := context.Get(r, routeKey); rv != nil { return rv.(*Route) From 13c8226081008f7ade9c619da744ed14e78eb8de Mon Sep 17 00:00:00 2001 From: Orne Brocaar Date: Wed, 5 Aug 2015 10:24:37 +0200 Subject: [PATCH 2/2] Update comment and specify KeepContext option. --- mux.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mux.go b/mux.go index 4a94a23..002051f 100644 --- a/mux.go +++ b/mux.go @@ -312,9 +312,10 @@ func Vars(r *http.Request) map[string]string { } // CurrentRoute returns the matched route for the current request, if any. -// Note: this only works when called inside the handler of the matched route -// because it uses context.Get() which will be cleared after executing the -// handler. +// This only works when called inside the handler of the matched route +// because the matched route is stored in the request context which is cleared +// after the handler returns, unless the KeepContext option is set on the +// Router. func CurrentRoute(r *http.Request) *Route { if rv := context.Get(r, routeKey); rv != nil { return rv.(*Route)