Fatalf("Failed to start the server: %v", err) | 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) | |||||
} |
So(response.Header().Get("Content-Type"), ShouldEqual, "application/json") | 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) | |||||
}) | |||||
} |
package rex | 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) | |||||
} |