First path param in group must be the same for all routes


#1

Hello, world!

I’ve noticed a situation with a path parameter inside a group (echo v3.3.6 and below).

For this configuration:

e := echo.New()

g := e.Group("/users")

g.GET("/:id/items", func(c echo.Context) error {
	c.JSON(http.StatusOK, struct {
		Result string
		Params []string
	}{
		Result: fmt.Sprintf("User GET: %s", c.Param("id")),
		Params: c.ParamNames(),
	})

	return nil
})

g.POST("/:uuid/items", func(c echo.Context) error {
	c.JSON(http.StatusOK, struct {
		Result string
		Params []string
	}{
		Result: fmt.Sprintf("User POST: id = %s; uuid = %s", c.Param("id"), c.Param("uuid")),
		Params: c.ParamNames(),
	})

	return nil
})

The GET call returns: {“Result”:“User GET: 2”,“Params”:[“id”]}
While POST returns: {“Result”: "User POST: id = 2; uuid = ", “Params”: [ “id” ]}

The first parameter inside a group must be the same. Even if I use “uuid” on POST, “id” is being used.
If I first define the POST route, the situation is reversed and “uuid” is used.

Is this behavior intended to force a good design?

The real use case for me was when I started transitioning numeric IDs to UUIDs. The application is too large to update all the routes and entities at once, so I wanted to do it in time, but to use “uuid” as param name, to make it clear where an uuid is necessary and where the numeric id is still used.

Thank you!