Confirm expected behavior of route naming in Echo v5 #3112
|
I’m using Echo v5 and I noticed a difference between the route registration API and the route metadata returned by In v5, ri := e.GET("/users/:id", handler)
ri.Name = "user-detail"does not affect the actual route registered in the router. I expected the route name to be settable after registration, similar to how v4 allowed mutating the returned Example: e := echo.New()
ri := e.GET("/users/:id", handler)
ri.Name = "user-detail"
fmt.Println(ri.Name) // "user-detail"
fmt.Println(e.Router().Routes()[0].Name) // likely still "GET:/users/:id"I’d like to confirm whether this is:
If it is expected, could you clarify the correct v5 pattern for naming routes? For example, is Thanks. |
Replies: 1 comment
|
yes, it is identended behavior in In handler := func(c *echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
}
_, _ := e.AddRoute(echo.Route{
Method: http.MethodGet,
Path: "/test",
Name: "my-route",
Handler: handler,
Middlewares: nil,
})If you want to rename route - it has to be reregistered. and possibily configure router to allow overwriting e := echo.NewWithConfig(echo.Config{
Router: echo.NewRouter(echo.RouterConfig{
AllowOverwritingRoute: false,
}),
}) |
yes, it is identended behavior in
v5that when you add a route the result is not a mutable (pointer).In
v5if you want to create named route you need to do:If you want to rename route - it has to be reregistered. and possibily configure router to allow overwriting