Skip to content

Commit 7f3595b

Browse files
committed
handle wildcard route
1 parent 9e44bcd commit 7f3595b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

router.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ func (r *Route) match(path string) (bool, map[string]string) {
118118
if strings.HasPrefix(part, ":") {
119119
paramName := strings.TrimPrefix(part, ":")
120120
params[paramName] = parts[i]
121+
} else if part == "*" {
122+
return true, params
121123
} else if part != parts[i] {
122124
return false, nil
123125
}

router_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import (
1010
func TestRouterHandler(t *testing.T) {
1111
router := New()
1212

13-
router.Post("/users/:id/:name", func(ctx *Context) error {
14-
param := ctx.Param("name")
15-
ctx.String(param)
13+
router.Get("/users/*", func(ctx *Context) error {
1614
ctx.String("hello")
1715
return nil
1816
})

0 commit comments

Comments
 (0)