Echo: Params are mixed between routes

Created on 28 May 2018  ·  4Comments  ·  Source: labstack/echo

Edit

it's appear that my problem is due to the fact that params in routes must have the same name between methods if they are at the same position.

If it's the case feel free to close this issue.

Working code to debug

package main

import (
    "log"
    "net/http"

    "github.com/labstack/echo"
)

func main() {
    e := echo.New()
    e.GET("/order/:shopid", func(c echo.Context) error {
        return c.NoContent(http.StatusOK)
    })
    e.DELETE("/order/:ref", func(c echo.Context) error {
        log.Printf("params %v", c.ParamNames())
        foo := c.Param("ref")
        return c.String(http.StatusOK, foo)
    })
    e.Logger.Fatal(e.Start("127.0.0.1:8080"))
}

Expected behaviour

curl -X DELETE http://127.0.0.1:8080/order/toto

  • should output "toto"
  • log should be: 2018/05/28 11:24:25 params [ref]

Actual behaviour

  • no output (foo=="")
  • log is 2018/05/28 11:24:25 params [shopid]

=> routing is correct, the good controler was executed in both case, but params binding are from GET /order/:shopid/pending route

Version

V3.3.dev

bug

Most helpful comment

+1
I have met the same problem.

Bellow is my code. In the second router, the path param's name should be "id", but it get nothing. I print all the path params, there is only "tid" lefted.

package main

import (
    "fmt"
    "github.com/labstack/echo"
)

func main() {

    // Echo instance
    e := echo.New()

    e.GET("/teacher/:tid/room/suggestions", func(c echo.Context) error {

        fmt.Printf("c.ParamNames() ", c.ParamNames())
        return nil
    })

    // 老师个人主页, 这个路由要放前面
    e.GET("/teacher/:id", func(c echo.Context) error {
        fmt.Printf("teacher-index parmas %d %#v", c.Param("id"), c.ParamNames())

        //teacher-index parmas  , []string{"tid"}

        return nil
    })

    e.Start(":1323")
}

All 4 comments

+1
I have met the same problem.

Bellow is my code. In the second router, the path param's name should be "id", but it get nothing. I print all the path params, there is only "tid" lefted.

package main

import (
    "fmt"
    "github.com/labstack/echo"
)

func main() {

    // Echo instance
    e := echo.New()

    e.GET("/teacher/:tid/room/suggestions", func(c echo.Context) error {

        fmt.Printf("c.ParamNames() ", c.ParamNames())
        return nil
    })

    // 老师个人主页, 这个路由要放前面
    e.GET("/teacher/:id", func(c echo.Context) error {
        fmt.Printf("teacher-index parmas %d %#v", c.Param("id"), c.ParamNames())

        //teacher-index parmas  , []string{"tid"}

        return nil
    })

    e.Start(":1323")
}

I met similar problem in version 3.3.dev for echo, and go version go1.10.3 linux/amd64 for golang.

My code is:

    e.POST("/axb/:xmode", handler.bindAXB)
    e.DELETE("/axb/:bindid", handler.unbindAXB)

And when I send command of HTTPIE

http delete 127.0.0.1:9990/axb/112233

in method handle.unbindAXB, the parameter is xmode, the parameter for method POST, but not bindid, the parameter for method DELETE, which means that in code below

func (this *axbHandler) unbindAXB(c echo.Context) error {
    bindID := c.Param("bindid")

The data in variable bindID is "" but not "112233".

@vishr Is this resolved with #1201?

@toorop Can you check if this is fixed?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mmindenhall picture mmindenhall  ·  4Comments

leoycx picture leoycx  ·  4Comments

vishr picture vishr  ·  3Comments

arun0009 picture arun0009  ·  3Comments

younisshah picture younisshah  ·  4Comments