about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFranck Cuny <franck@lumberjaph.net>2013-04-27 10:47:28 -0700
committerFranck Cuny <franck@lumberjaph.net>2013-04-27 10:47:28 -0700
commitc9a6fc2338a6abb19dcbffe38578c4d4736f0b4d (patch)
tree9d3fc4b35c8342347bf399ae29e17ea99ca0f92a
parentSupport default value for placeholders in route's path. (diff)
downloadpath-router-c9a6fc2338a6abb19dcbffe38578c4d4736f0b4d.tar.gz
Add GetRouteList to the Router.
This function return a list of path known by the router.
-rw-r--r--router.go9
-rw-r--r--router_test.go16
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()
+	}
+}