Skip to content

Commit 2d77bcd

Browse files
committed
adjust the routergroup Any method (gin-gonic#2701)
1 parent b799a30 commit 2d77bcd

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

routergroup.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ import (
1414
var (
1515
// reg match english letters for http method name
1616
regEnLetter = regexp.MustCompile("^[A-Z]+$")
17+
18+
// anyMethods for RouterGroup Any method
19+
anyMethods = []string{
20+
http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch,
21+
http.MethodHead, http.MethodOptions, http.MethodDelete, http.MethodConnect,
22+
http.MethodTrace,
23+
}
1724
)
1825

1926
// IRouter defines all router handle interface includes single and group router.
@@ -136,15 +143,10 @@ func (group *RouterGroup) HEAD(relativePath string, handlers ...HandlerFunc) IRo
136143
// Any registers a route that matches all the HTTP methods.
137144
// GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE.
138145
func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) IRoutes {
139-
group.handle(http.MethodGet, relativePath, handlers)
140-
group.handle(http.MethodPost, relativePath, handlers)
141-
group.handle(http.MethodPut, relativePath, handlers)
142-
group.handle(http.MethodPatch, relativePath, handlers)
143-
group.handle(http.MethodHead, relativePath, handlers)
144-
group.handle(http.MethodOptions, relativePath, handlers)
145-
group.handle(http.MethodDelete, relativePath, handlers)
146-
group.handle(http.MethodConnect, relativePath, handlers)
147-
group.handle(http.MethodTrace, relativePath, handlers)
146+
for _, method := range anyMethods {
147+
group.handle(method, relativePath, handlers)
148+
}
149+
148150
return group.returnObj()
149151
}
150152

0 commit comments

Comments
 (0)