Skip to content

Commit e20fba3

Browse files
committed
add comment
1 parent 99eab04 commit e20fba3

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

modules/web/router_path.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ func (g *RouterPathGroup) ServeHTTP(resp http.ResponseWriter, req *http.Request)
3737
g.r.chiRouter.NotFoundHandler().ServeHTTP(resp, req)
3838
}
3939

40+
// MatchPath matches the request method, and uses regexp to match the path.
41+
// The pattern uses "<...>" to define path parameters, for example: "/<name>" (different from chi router)
4042
func (g *RouterPathGroup) MatchPath(methods, pattern string, h ...any) {
4143
g.processors = append(g.processors, newRouterPathMatcher(methods, pattern, h...))
4244
}

modules/web/router_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func TestPathProcessor(t *testing.T) {
3838
assert.True(t, p.matchPath(chiCtx, uri), "use pattern %s to process uri %s", pattern, uri)
3939
assert.Equal(t, expectedPathParams, chiURLParamsToMap(chiCtx), "use pattern %s to process uri %s", pattern, uri)
4040
}
41+
42+
// the "<...>" is intentionally designed to distinguish from chi's path parameters, because:
43+
// 1. their behaviors are totally different, we do not to mislead developers
44+
// 2. we can write regexp in "<name:\w{3,4}>" easily and parse it easily
4145
testProcess("/<p1>/<p2>", "/a/b", map[string]string{"p1": "a", "p2": "b"})
4246
testProcess("/<p1:*>", "", map[string]string{"p1": ""}) // this is a special case, because chi router could use empty path
4347
testProcess("/<p1:*>", "/", map[string]string{"p1": ""})

0 commit comments

Comments
 (0)