mirror of https://github.com/gin-gonic/gin.git
chore(router): match method added to routergroup for multiple HTTP methods supporting (#3464)
This commit is contained in:
parent
c5fd06361b
commit
e02ae6ae61
|
@ -42,6 +42,7 @@ type IRoutes interface {
|
|||
PUT(string, ...HandlerFunc) IRoutes
|
||||
OPTIONS(string, ...HandlerFunc) IRoutes
|
||||
HEAD(string, ...HandlerFunc) IRoutes
|
||||
Match([]string, string, ...HandlerFunc) IRoutes
|
||||
|
||||
StaticFile(string, string) IRoutes
|
||||
StaticFileFS(string, string, http.FileSystem) IRoutes
|
||||
|
@ -151,6 +152,15 @@ func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) IRou
|
|||
return group.returnObj()
|
||||
}
|
||||
|
||||
// Match registers a route that matches the specified methods that you declared.
|
||||
func (group *RouterGroup) Match(methods []string, relativePath string, handlers ...HandlerFunc) IRoutes {
|
||||
for _, method := range methods {
|
||||
group.handle(method, relativePath, handlers)
|
||||
}
|
||||
|
||||
return group.returnObj()
|
||||
}
|
||||
|
||||
// StaticFile registers a single route in order to serve a single file of the local filesystem.
|
||||
// router.StaticFile("favicon.ico", "./resources/favicon.ico")
|
||||
func (group *RouterGroup) StaticFile(relativePath, filepath string) IRoutes {
|
||||
|
|
|
@ -186,6 +186,7 @@ func testRoutesInterface(t *testing.T, r IRoutes) {
|
|||
assert.Equal(t, r, r.PUT("/", handler))
|
||||
assert.Equal(t, r, r.OPTIONS("/", handler))
|
||||
assert.Equal(t, r, r.HEAD("/", handler))
|
||||
assert.Equal(t, r, r.Match([]string{http.MethodPut, http.MethodPatch}, "/match", handler))
|
||||
|
||||
assert.Equal(t, r, r.StaticFile("/file", "."))
|
||||
assert.Equal(t, r, r.StaticFileFS("/static2", ".", Dir(".", false)))
|
||||
|
|
Loading…
Reference in New Issue