Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same path routing bug #479

Closed
ww24 opened this issue Apr 21, 2016 · 6 comments
Closed

Same path routing bug #479

ww24 opened this issue Apr 21, 2016 · 6 comments
Assignees
Milestone

Comments

@ww24
Copy link

ww24 commented Apr 21, 2016

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. 😢

@vishr vishr self-assigned this Apr 21, 2016
@vishr vishr added the question label Apr 21, 2016
@vishr
Copy link
Member

vishr commented Apr 21, 2016

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).

@ww24
Copy link
Author

ww24 commented Apr 21, 2016

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

@vishr
Copy link
Member

vishr commented Apr 21, 2016

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

@fundon
Copy link

fundon commented Aug 2, 2016

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

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

@chenjie4255
Copy link

+1, having a same problem :(

@vishr vishr mentioned this issue Aug 22, 2016
@vishr vishr added this to the v3 milestone Oct 11, 2016
@alfg
Copy link

alfg commented Nov 14, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants