Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Maintain a list of routes and their methods.

This is useful for future introspection features.
  • Loading branch information...
commit b494d7a2b43d3d1c508bcb065177ad04a2152e23 1 parent 07b73f6
@franckcuny authored
Showing with 21 additions and 1 deletion.
  1. +21 −1 trie/impl.go
View
22 trie/impl.go
@@ -235,16 +235,32 @@ func New() *Trie {
}
}
+var routes = map[string]map[string]bool{}
+
+func updateRoutes(path string, method string) {
+ if routes[path] == nil {
+ routes[path] = map[string]bool{method: true}
+ } else {
+ routes[path][method] = true
+ }
+}
+
// Insert the route in the Trie following or creating the nodes corresponding to the path.
func (self *Trie) AddRoute(path string, method string, route interface{}) error {
if method != "" {
- return self.root.addRoute(path, method, route)
+ err := self.root.addRoute(path, method, route)
+ if err == nil {
+ updateRoutes(path, method)
+ }
+ return err
}
for _, defaultMethod := range HttpDefaultMethods {
err := self.root.addRoute(path, defaultMethod, route)
if err != nil {
return err
+ } else {
+ updateRoutes(path, method)
}
}
return nil
@@ -259,3 +275,7 @@ func (self *Trie) FindRoutes(path string, method string) []*Match {
func (self *Trie) Compress() {
self.root.compress()
}
+
+func (self *Trie) AllRoutes() map[string]map[string]bool {
+ return routes
+}
Please sign in to comment.
Something went wrong with that request. Please try again.