summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--router.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/router.go b/router.go
index 193d076..86d706a 100644
--- a/router.go
+++ b/router.go
@@ -19,13 +19,17 @@ func NewRouter() *Router {
return &Router{}
}
+func (r *Router) splitPath(path string) []string {
+ return strings.Split(strings.Trim(path, "/"), "/")
+}
+
func (r *Router) Add(method string, path string, h Handler) {
- parts := strings.Split(path, "/")
+ parts := r.splitPath(path)
r.routes = append(r.routes, route{method, parts, h})
}
func (r *Router) Find(method string, path string) (Handler, map[string]string) {
- parts := strings.Split(path, "/")
+ parts := r.splitPath(path)
for _, rt := range r.routes {
// match HTTP method