Skip to content

Commit

Permalink
Fixed search in MethodsFor
Browse files Browse the repository at this point in the history
  • Loading branch information
shirro committed Feb 9, 2014
1 parent 1e9553f commit 46fea46
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ func hasMethod(methods []string, method string) bool {
func (r routes) MethodsFor(path string) []string {
methods := []string{}
for _, route := range r.router.routes {
if route.regex.MatchString(path) && !hasMethod(methods, route.method) {
matches := route.regex.FindStringSubmatch(path)
if len(matches) > 0 && matches[0] == path && !hasMethod(methods, route.method) {
methods = append(methods, route.method)
}
}
Expand Down
3 changes: 3 additions & 0 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ func Test_MethodsFor(t *testing.T) {
router.Post("/foo/bar", func() {
})

router.Post("/fo", func() {
})

router.Get("/foo", func() {
})

Expand Down

0 comments on commit 46fea46

Please sign in to comment.