mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 21:32:11 +08:00
Merge 05736c6b1b91cc114ee380c0dc4ff93341b4556e into 1c48977cca9e7a0a41c763376b6921a23cd06fe2
This commit is contained in:
commit
718b704c07
@ -34,6 +34,7 @@ type IRoutes interface {
|
||||
Use(...HandlerFunc) IRoutes
|
||||
|
||||
Handle(string, string, ...HandlerFunc) IRoutes
|
||||
Handles([]string, string, ...HandlerFunc) IRoutes
|
||||
Any(string, ...HandlerFunc) IRoutes
|
||||
GET(string, ...HandlerFunc) IRoutes
|
||||
POST(string, ...HandlerFunc) IRoutes
|
||||
@ -106,6 +107,19 @@ func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...Ha
|
||||
return group.handle(httpMethod, relativePath, handlers)
|
||||
}
|
||||
|
||||
// Handles registers multiple new request handle with the given path and method.
|
||||
// Its specific usage is the same as the Handle method, but it supports setting multiple http methods at the same time.
|
||||
func (group *RouterGroup) Handles(httpMethods []string, relativePath string, handlers ...HandlerFunc) IRoutes {
|
||||
for _, method := range httpMethods {
|
||||
if matched := regEnLetter.MatchString(method); !matched {
|
||||
panic("http method " + method + " is not valid")
|
||||
}
|
||||
group.handle(method, relativePath, handlers)
|
||||
}
|
||||
|
||||
return group.returnObj()
|
||||
}
|
||||
|
||||
// POST is a shortcut for router.Handle("POST", path, handle).
|
||||
func (group *RouterGroup) POST(relativePath string, handlers ...HandlerFunc) IRoutes {
|
||||
return group.handle(http.MethodPost, relativePath, handlers)
|
||||
|
@ -178,6 +178,7 @@ func testRoutesInterface(t *testing.T, r IRoutes) {
|
||||
assert.Equal(t, r, r.Use(handler))
|
||||
|
||||
assert.Equal(t, r, r.Handle(http.MethodGet, "/handler", handler))
|
||||
assert.Equal(t, r, r.Handles([]string{http.MethodGet, http.MethodHead, http.MethodPost}, "/handlers", handler))
|
||||
assert.Equal(t, r, r.Any("/any", handler))
|
||||
assert.Equal(t, r, r.GET("/", handler))
|
||||
assert.Equal(t, r, r.POST("/", handler))
|
||||
|
Loading…
x
Reference in New Issue
Block a user