@@ -141,3 +141,8 @@ func (self *Router) Run() { | |||
Fatalf("Failed to start the server: %v", err) | |||
} | |||
} | |||
// Vars returns the route variables for the current request, if any. | |||
func (self *Router) Vars(r *http.Request) map[string]string { | |||
return mux.Vars(r) | |||
} |
@@ -122,3 +122,17 @@ func TestUse(t *testing.T) { | |||
So(response.Header().Get("Content-Type"), ShouldEqual, "application/json") | |||
}) | |||
} | |||
func TestVars(t *testing.T) { | |||
Convey("rex.Vars", t, func() { | |||
app := New() | |||
app.Get("/users/{id}", func(w http.ResponseWriter, r *http.Request) { | |||
vars := app.Vars(r) | |||
So(vars["id"], ShouldEqual, "123") | |||
}) | |||
request, _ := http.NewRequest("GET", "/users/123", nil) | |||
response := httptest.NewRecorder() | |||
app.ServeHTTP(response, request) | |||
}) | |||
} |
@@ -1,12 +1 @@ | |||
package rex | |||
import ( | |||
"net/http" | |||
"github.com/gorilla/mux" | |||
) | |||
// Vars returns the route variables for the current request, if any. | |||
func Vars(r *http.Request) map[string]string { | |||
return mux.Vars(r) | |||
} |