mirror of
https://github.com/go-kratos/kratos.git
synced 2026-05-22 10:15:24 +02:00
add sub router for http
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
func sayHelloHandler(ctx http.Context) error {
|
||||
var in helloworld.HelloRequest
|
||||
if err := ctx.Bind(&in); err != nil {
|
||||
if err := ctx.BindQuery(&in); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,10 @@ 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)
|
||||
r2.GET("/say/{name}", sayHelloHandler)
|
||||
|
||||
app := kratos.New(
|
||||
kratos.Name("helloworld"),
|
||||
kratos.Server(
|
||||
|
||||
Reference in New Issue
Block a user