From c9a6fc2338a6abb19dcbffe38578c4d4736f0b4d Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Sat, 27 Apr 2013 10:47:28 -0700 Subject: Add GetRouteList to the Router. This function return a list of path known by the router. --- router.go | 9 +++++++-- router_test.go | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/router.go b/router.go index 8612ad2..3985780 100644 --- a/router.go +++ b/router.go @@ -89,8 +89,13 @@ func (self *Router) disambiguateMatches(path string, matches []*Match) (*Match, return found[0], nil } -// func (*dispatcher) ListRoutes() { -// } +func (self *Router) GetRouteList() []string { + routes := make([]string, len(self.routes)) + for i, r := range self.routes{ + routes[i] = r.Path + } + return routes +} // func (*dispatcher) AddRoutes() { // } diff --git a/router_test.go b/router_test.go index df67607..a9826ba 100644 --- a/router_test.go +++ b/router_test.go @@ -20,3 +20,19 @@ func testBasic(t *testing.T) { t.Fatal() } } + +func TestGetRouteList(t *testing.T) { + r := BuildRouter() + r.AddRoute(&Route{Method: "GET", Path: "/foo", Code: testRoute}) + r.AddRoute(&Route{Method: "GET", Path: "/bar", Code: testRoute}) + r.AddRoute(&Route{Method: "GET", Path: "/baz", Code: testRoute}) + + routes := r.GetRouteList() + if len(routes) != 3 { + t.Fatal() + } + + if routes[0] != "/foo" { + t.Fatal() + } +} -- cgit 1.4.1