Echo: Same path routing bug

Created on 21 Apr 2016  路  6Comments  路  Source: labstack/echo

Is this behavior a bug?

package main

import (
    "net/http"

    "github.com/labstack/echo"
    "github.com/labstack/echo/engine/standard"
)

func main() {
    e := echo.New()

    e.GET("/:piyo", func(c echo.Context) error {
        return c.String(http.StatusOK, "fail: "+c.Param("piyo"))
    })
    e.POST("/:hoge", func(c echo.Context) error {
        return c.String(http.StatusOK, "success: "+c.Param("hoge"))
    })

    e.Run(standard.New(":1323"))
}

c.Param("piyo") is empty. 馃槩

enhancement question

Most helpful comment

Thanks. But, this behavior is unintelligible.
I want to use different params for code readability.

All 6 comments

It is like that. In this case :piyo is overridden by :hoge; you should use the same name and if that doesn't work get it by index Context.P(0).

Thanks. But, this behavior is unintelligible.
I want to use different params for code readability.

I understand. I will keep this issue open and give it a thought later.

Maybe, IMO https://github.com/trekjs/router/blob/master/index.js

node.maps = {
   'GET': {
      pnames,
      handler
   }
}

+1, having a same problem :(

Same issue here. It would be great for the scenario below:

e.Get("/users/:id", handlers.GetUserByID)
e.Get("/users/:name", handlers.GetUserByName)
e.Put("/users/:id", handlers.UpdateUserByID)

In this case, c.Param("name") doesn't work for the 2nd route above. I will use Context.P(0) for now, though.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leoycx picture leoycx  路  4Comments

syntaqx picture syntaqx  路  3Comments

danieldaeschle picture danieldaeschle  路  3Comments

neutronstein picture neutronstein  路  3Comments

vishr picture vishr  路  3Comments