Skip to content

Commit e02ae6a

Browse files
chore(router): match method added to routergroup for multiple HTTP methods supporting (#3464)
1 parent c5fd063 commit e02ae6a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

routergroup.go

+10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type IRoutes interface {
4242
PUT(string, ...HandlerFunc) IRoutes
4343
OPTIONS(string, ...HandlerFunc) IRoutes
4444
HEAD(string, ...HandlerFunc) IRoutes
45+
Match([]string, string, ...HandlerFunc) IRoutes
4546

4647
StaticFile(string, string) IRoutes
4748
StaticFileFS(string, string, http.FileSystem) IRoutes
@@ -151,6 +152,15 @@ func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) IRou
151152
return group.returnObj()
152153
}
153154

155+
// Match registers a route that matches the specified methods that you declared.
156+
func (group *RouterGroup) Match(methods []string, relativePath string, handlers ...HandlerFunc) IRoutes {
157+
for _, method := range methods {
158+
group.handle(method, relativePath, handlers)
159+
}
160+
161+
return group.returnObj()
162+
}
163+
154164
// StaticFile registers a single route in order to serve a single file of the local filesystem.
155165
// router.StaticFile("favicon.ico", "./resources/favicon.ico")
156166
func (group *RouterGroup) StaticFile(relativePath, filepath string) IRoutes {

routergroup_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ func testRoutesInterface(t *testing.T, r IRoutes) {
186186
assert.Equal(t, r, r.PUT("/", handler))
187187
assert.Equal(t, r, r.OPTIONS("/", handler))
188188
assert.Equal(t, r, r.HEAD("/", handler))
189+
assert.Equal(t, r, r.Match([]string{http.MethodPut, http.MethodPatch}, "/match", handler))
189190

190191
assert.Equal(t, r, r.StaticFile("/file", "."))
191192
assert.Equal(t, r, r.StaticFileFS("/static2", ".", Dir(".", false)))

0 commit comments

Comments
 (0)