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

context doesn't capture "Group" params #49

Closed
tve opened this issue May 5, 2015 · 8 comments
Closed

context doesn't capture "Group" params #49

tve opened this issue May 5, 2015 · 8 comments
Assignees
Labels

Comments

@tve
Copy link

tve commented May 5, 2015

The request params that are part of the Group prefix are not captured correctly. Here's a test program:

package main

import (
        "fmt"

        "github.com/labstack/echo"
)

func main() {
        e := echo.New()
        gr := e.Group("/acct/:a")
        gr.Get("/hello", helloHandler)
        e.Run(":4444")
}

func helloHandler(c *echo.Context) {
        c.String(200, fmt.Sprintf("Hello World!\nacct: %s\n%#v\n", c.Param("acct"), *c))
}

and a simple test:

2$ go run main.go &
[1] 1485
tve@h:/home/src/github.com/rightscale/uca/bug2$ curl http://localhost:4444/acct/123/hello
Hello World!
acct:
echo.Context{Request:(*http.Request)(0xc2080325b0), Response:(*echo.response)(0xc20803ac90), pnames:[]string(nil), pvalues:[]string{"123", "", "", "", ""}, store:echo.store{}, echo:(*echo.Echo)(0xc208066080)}

You can see that the 'acct' param is empty, but in the context the value of the param was captured but not the name. Am I doing something wrong?

@vishr
Copy link
Member

vishr commented May 5, 2015

@tve Let me think over it, I never thought this way ;)

@tve
Copy link
Author

tve commented May 5, 2015

Cool, thanks for fixing!
You still have a problem with a trailing slash:

$ curl http://localhost:4444/acct/123/hello/
2015/05/04 21:44:20 http: panic serving [::1]:38441: runtime error: index out of range
goroutine 6 [running]:
net/http.func·011()
        /big/usr-local/go/src/net/http/server.go:1130 +0xbb
github.com/labstack/echo.(*router).Find(0xc20800a750, 0xc20801e4e0, 0x3, 0xc20801e4e4, 0x10, 0xc208040550, 0x0, 0x0)
        /home/src/github.com/labstack/echo/router.go:256 +0x407
github.com/labstack/echo.(*Echo).ServeHTTP(0xc208066000, 0x7f5e901a70d0, 0xc2080443c0, 0xc208032820)
        /home/src/github.com/labstack/echo/echo.go:296 +0xd0

@tve
Copy link
Author

tve commented May 8, 2015

Can you ack this issue or do I need to fork & fix myself? Thanks!

@vishr
Copy link
Member

vishr commented May 8, 2015

I tried to fix it but it opened a can of worms. I am gonna give it a shot over the weekend, just hang on.

@vishr vishr reopened this May 8, 2015
@vishr
Copy link
Member

vishr commented May 10, 2015

c58ec74

@vishr vishr closed this as completed May 10, 2015
@vishr vishr added the bug label May 10, 2015
@vishr vishr self-assigned this May 10, 2015
@vishr
Copy link
Member

vishr commented May 14, 2015

18dcc4b

@ghost
Copy link

ghost commented Aug 20, 2015

Potentially a similar issue, I'm seeing group middleware with a wildcard group.Get match return the wrong url segment in the param value.

// instead of getting "labstack" from c.Param("thing"), I get "rules"
GET /v1/labstack/rules

func main() {
  e = echo.New()
  g := e.Group("/v1/:thing")
  g.Use(ThingMiddleware)
  g.Get("/*", Handle)
  e.Run(":1234")
}

func ThingMiddleware() echo.HandlerFunc {
  return func(c *echo.Context) error {
    log.Println(c.Param("thing"))
    return nil
  }
}

func Handle(c *echo.Context) error {
  return c.String(200, c.Param("thing"))
}

@vishr
Copy link
Member

vishr commented Aug 20, 2015

@laicosly Looks like a bug when used with wildcard, it's the same even without using a group e.g. e.Get("/v1/:thing/*, Handle). Can you create a separate issue?

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

No branches or pull requests

2 participants