gin-gonic / gin

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
https://gin-gonic.com/
MIT License
78.23k stars 7.98k forks source link

the Catch-All form should not include the "/" before param #279

Open jostyee opened 9 years ago

jostyee commented 9 years ago

As the doc said,

r.GET("/user/:name/*action"...
action := c.Params.ByName("action")

should return value string of action, but in fact it returns /action with the slash before param string, which is not correctly & inconvenient.

manucorporat commented 9 years ago

which branch are you using?

manucorporat commented 9 years ago

Ok, Gin uses httpRouter. https://github.com/julienschmidt/httprouter/issues/77

This was already reported and it was marked as an intentional behaviour according to the author.

Since v1, Gin is not longer dependent on httpRouter, so I am open to discussion.

nazwa commented 9 years ago

@manucorporat, when do you think you'll be releasing the new super fast router? :)

jostyee commented 9 years ago

@manucorporat this behaviour is really counterintuitive, please consider removing it in future.

manucorporat commented 9 years ago

@iyee I agree

@julienschmidt said that it is that way because /{EMPTY} also matches, well then *action=""

/path/to/*wildcard
/path/to/something ---> 200 "wildcard": "something"
/path/to/ ---> 200 "wildcard": ""
/path/to ---> 301 or 404 "wildcard" param does not exist
manucorporat commented 9 years ago

I understand the reasons of @julienschmidt but:

You bought a new car. You took it out for a ride. a tree falls before you. You brake, but the car proceeded to hit the tree anyway. You call the car company and talk to their engineers. One of them ask. 'Did this happen on a Friday evening, when it was raining?' You say 'Yes, how do you know?' The engineer replies. "Our brakes does not work on rainy Friday evenings. If you REALLY want to brake on a rainy Friday evening, you should also pull the lever under the dash board that is normally used to open the hood. It is very clearly printed on our manual. Didn't you read it? Our car is not the problem. You are the problem" You were enlightened. You came back home. You never took the car out on rainy Friday evenings. When Somebody asks about the car, You said. "Yea, it is a great car. But you got to know how to use it". You took great pride in knowing how to drive this car, which can easily kill someone who hasn't read the manual. When you hear that someone got killed while driving this car, you simply said. 'That car is Ok. but you should really know how to drive it, sadly this guy didn't. He was the problem, the car ain't...

https://news.ycombinator.com/item?id=9485741

manucorporat commented 9 years ago

@iyee Check out this work in progress: https://github.com/gin-gonic/gin/commit/42e0c82bf4f243ea7342bd9e8baeb76882fc63d4