1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-05 22:53:41 +02:00

add router group for http server (#1208)

This commit is contained in:
longxboy 2021-07-18 20:12:20 +08:00 committed by GitHub
parent 078ca6bc9b
commit 4e529d1e30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -30,8 +30,8 @@ func main() {
// add path filter to custom route
r.GET("/hello/{name}", sayHelloHandler, pathFilter, pathFilter2)
// add path filter to sub router
r2 := r.NewSubRouter("/v2", pathFilter, pathFilter2)
// add path filter to router group
r2 := r.Group("/v2", pathFilter, pathFilter2)
r2.GET("/say/{name}", sayHelloHandler)
app := kratos.New(

View File

@ -29,8 +29,8 @@ func newRouter(prefix string, srv *Server, filters ...FilterFunc) *Router {
return r
}
// NewSubRouter returns a new sub router
func (r *Router) NewSubRouter(prefix string, filters ...FilterFunc) *Router {
// Group returns a new router group.
func (r *Router) Group(prefix string, filters ...FilterFunc) *Router {
var newFilters []FilterFunc
newFilters = append(newFilters, r.filters...)
newFilters = append(newFilters, filters...)