Refactor package (routes and error handling, npm peer dependency) (#33111)

This commit is contained in:
wxiaoguang
2025-01-06 22:45:20 +08:00
committed by GitHub
parent ef736b7e27
commit 80e4f4c4eb
28 changed files with 153 additions and 244 deletions

View File

@ -89,11 +89,23 @@ func (p *routerPathMatcher) matchPath(chiCtx *chi.Context, path string) bool {
return true
}
func isValidMethod(name string) bool {
switch name {
case http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete, http.MethodHead, http.MethodOptions, http.MethodConnect, http.MethodTrace:
return true
}
return false
}
func newRouterPathMatcher(methods, pattern string, h ...any) *routerPathMatcher {
middlewares, handlerFunc := wrapMiddlewareAndHandler(nil, h)
p := &routerPathMatcher{methods: make(container.Set[string]), middlewares: middlewares, handlerFunc: handlerFunc}
for _, method := range strings.Split(methods, ",") {
p.methods.Add(strings.TrimSpace(method))
method = strings.TrimSpace(method)
if !isValidMethod(method) {
panic(fmt.Sprintf("invalid HTTP method: %s", method))
}
p.methods.Add(method)
}
re := []byte{'^'}
lastEnd := 0