add router group for http server (#1208)

pull/1209/head
longxboy 3 years ago committed by GitHub
parent 078ca6bc9b
commit 4e529d1e30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      examples/http/middlewares/main.go
  2. 4
      transport/http/router.go

@ -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(

@ -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...)

Loading…
Cancel
Save