Skip to content

Same path routing bug #479

Closed
Closed

Description

@ww24

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

Activity

  1. self-assigned this
    on Apr 21, 2016
  2. vishr commented on Apr 21, 2016

    @vishr
    Member

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

  3. ww24 commented on Apr 21, 2016

    @ww24
    Author

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

  4. vishr commented on Apr 21, 2016

    @vishr
    Member

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

  5. fundon commented on Aug 2, 2016

    @fundon
  6. chenjie4255 commented on Aug 8, 2016

    @chenjie4255

    +1, having a same problem :(

  7. added this to the v3 milestone on Oct 11, 2016
  8. alfg commented on Nov 14, 2016

    @alfg

    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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions