mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-07 23:02:12 +02:00
add router group for http server (#1208)
This commit is contained in:
parent
078ca6bc9b
commit
4e529d1e30
@ -30,8 +30,8 @@ func main() {
|
|||||||
// add path filter to custom route
|
// add path filter to custom route
|
||||||
r.GET("/hello/{name}", sayHelloHandler, pathFilter, pathFilter2)
|
r.GET("/hello/{name}", sayHelloHandler, pathFilter, pathFilter2)
|
||||||
|
|
||||||
// add path filter to sub router
|
// add path filter to router group
|
||||||
r2 := r.NewSubRouter("/v2", pathFilter, pathFilter2)
|
r2 := r.Group("/v2", pathFilter, pathFilter2)
|
||||||
r2.GET("/say/{name}", sayHelloHandler)
|
r2.GET("/say/{name}", sayHelloHandler)
|
||||||
|
|
||||||
app := kratos.New(
|
app := kratos.New(
|
||||||
|
@ -29,8 +29,8 @@ func newRouter(prefix string, srv *Server, filters ...FilterFunc) *Router {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSubRouter returns a new sub router
|
// Group returns a new router group.
|
||||||
func (r *Router) NewSubRouter(prefix string, filters ...FilterFunc) *Router {
|
func (r *Router) Group(prefix string, filters ...FilterFunc) *Router {
|
||||||
var newFilters []FilterFunc
|
var newFilters []FilterFunc
|
||||||
newFilters = append(newFilters, r.filters...)
|
newFilters = append(newFilters, r.filters...)
|
||||||
newFilters = append(newFilters, filters...)
|
newFilters = append(newFilters, filters...)
|
||||||
|
Loading…
Reference in New Issue
Block a user