mirror of
https://github.com/go-gitea/gitea
synced 2025-07-14 06:27:19 +00:00
Refactor some trivial problems (#34959)
1. make our "route group pattern match" also update chi's RoutePattern 2. fix incorrect "NotFound" call in conda package 3. make ".flex-item .flex-item-main" has a general gap, then no need to use `tw` tricks 4. improve the "test webhook" UI
This commit is contained in:
@ -26,6 +26,7 @@ func (g *RouterPathGroup) ServeHTTP(resp http.ResponseWriter, req *http.Request)
|
||||
path := chiCtx.URLParam(g.pathParam)
|
||||
for _, m := range g.matchers {
|
||||
if m.matchPath(chiCtx, path) {
|
||||
chiCtx.RoutePatterns = append(chiCtx.RoutePatterns, m.pattern)
|
||||
handler := m.handlerFunc
|
||||
for i := len(m.middlewares) - 1; i >= 0; i-- {
|
||||
handler = m.middlewares[i](handler).ServeHTTP
|
||||
@ -38,6 +39,7 @@ func (g *RouterPathGroup) ServeHTTP(resp http.ResponseWriter, req *http.Request)
|
||||
}
|
||||
|
||||
type RouterPathGroupPattern struct {
|
||||
pattern string
|
||||
re *regexp.Regexp
|
||||
params []routerPathParam
|
||||
middlewares []any
|
||||
@ -62,6 +64,7 @@ type routerPathParam struct {
|
||||
|
||||
type routerPathMatcher struct {
|
||||
methods container.Set[string]
|
||||
pattern string
|
||||
re *regexp.Regexp
|
||||
params []routerPathParam
|
||||
middlewares []func(http.Handler) http.Handler
|
||||
@ -117,7 +120,7 @@ func newRouterPathMatcher(methods string, patternRegexp *RouterPathGroupPattern,
|
||||
}
|
||||
p.methods.Add(method)
|
||||
}
|
||||
p.re, p.params = patternRegexp.re, patternRegexp.params
|
||||
p.pattern, p.re, p.params = patternRegexp.pattern, patternRegexp.re, patternRegexp.params
|
||||
return p
|
||||
}
|
||||
|
||||
@ -157,7 +160,7 @@ func patternRegexp(pattern string, h ...any) *RouterPathGroupPattern {
|
||||
p.params = append(p.params, param)
|
||||
}
|
||||
re = append(re, '$')
|
||||
p.re = regexp.MustCompile(string(re))
|
||||
p.pattern, p.re = pattern, regexp.MustCompile(string(re))
|
||||
return p
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user