Skip to content

Commit 46b952a

Browse files
committed
more comments
1 parent 6ba3818 commit 46b952a

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

modules/web/router.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ func (r *Router) Combo(pattern string, h ...any) *Combo {
248248
return &Combo{r, pattern, h}
249249
}
250250

251+
// PathGroup creates a group of paths which could be matched by regexp.
252+
// It is only designed to resolve some special cases which chi router can't handle.
253+
// For most cases, it shouldn't be used because it needs to iterate all rules to find the matched one (inefficient).
251254
func (r *Router) PathGroup(pattern string, fn func(g *RouterPathGroup), h ...any) {
252255
g := &RouterPathGroup{r: r, pathParam: "*"}
253256
fn(g)

modules/web/router_path.go

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

4040
// MatchPath matches the request method, and uses regexp to match the path.
4141
// The pattern uses "<...>" to define path parameters, for example: "/<name>" (different from chi router)
42+
// It is only designed to resolve some special cases which chi router can't handle.
43+
// For most cases, it shouldn't be used because it needs to iterate all rules to find the matched one (inefficient).
4244
func (g *RouterPathGroup) MatchPath(methods, pattern string, h ...any) {
4345
g.processors = append(g.processors, newRouterPathMatcher(methods, pattern, h...))
4446
}

routers/api/packages/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func CommonRoutes() *web.Router {
138138
}, reqPackageAccess(perm.AccessModeRead))
139139
r.Group("/arch", func() {
140140
r.Methods("HEAD,GET", "/repository.key", arch.GetRepositoryKey)
141-
r.PathGroup("/*", func(g *web.RouterPathGroup) {
141+
r.PathGroup("*", func(g *web.RouterPathGroup) {
142142
g.MatchPath("PUT", "/<repository:*>", reqPackageAccess(perm.AccessModeWrite), arch.UploadPackageFile)
143143
g.MatchPath("HEAD,GET", "/<repository:*>/<architecture>/<filename>", arch.GetPackageOrRepositoryFile)
144144
g.MatchPath("DELETE", "/<repository:*>/<name>/<version>/<architecture>", reqPackageAccess(perm.AccessModeWrite), arch.DeletePackageVersion)

0 commit comments

Comments
 (0)