Skip to content

Commit

Permalink
chore(router): match method added to routergroup for multiple HTTP me…
Browse files Browse the repository at this point in the history
…thods supporting (#3464)
  • Loading branch information
alirezaeftekhari authored Feb 6, 2023
1 parent c5fd063 commit e02ae6a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions routergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions routergroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit e02ae6a

Please sign in to comment.