adjust the routergroup Any method (#2701)

This commit is contained in:
heige 2021-10-24 09:31:13 +08:00 committed by GitHub
parent 2d3d6d2f13
commit eb75ce0ff5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 9 deletions

View File

@ -14,6 +14,13 @@ import (
var ( var (
// reg match english letters for http method name // reg match english letters for http method name
regEnLetter = regexp.MustCompile("^[A-Z]+$") regEnLetter = regexp.MustCompile("^[A-Z]+$")
// anyMethods for RouterGroup Any method
anyMethods = []string{
http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch,
http.MethodHead, http.MethodOptions, http.MethodDelete, http.MethodConnect,
http.MethodTrace,
}
) )
// IRouter defines all router handle interface includes single and group router. // IRouter defines all router handle interface includes single and group router.
@ -136,15 +143,10 @@ func (group *RouterGroup) HEAD(relativePath string, handlers ...HandlerFunc) IRo
// Any registers a route that matches all the HTTP methods. // Any registers a route that matches all the HTTP methods.
// GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE. // GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE.
func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) IRoutes { func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) IRoutes {
group.handle(http.MethodGet, relativePath, handlers) for _, method := range anyMethods {
group.handle(http.MethodPost, relativePath, handlers) group.handle(method, relativePath, handlers)
group.handle(http.MethodPut, relativePath, handlers) }
group.handle(http.MethodPatch, relativePath, handlers)
group.handle(http.MethodHead, relativePath, handlers)
group.handle(http.MethodOptions, relativePath, handlers)
group.handle(http.MethodDelete, relativePath, handlers)
group.handle(http.MethodConnect, relativePath, handlers)
group.handle(http.MethodTrace, relativePath, handlers)
return group.returnObj() return group.returnObj()
} }