Closed manucorporat closed 8 years ago
I actually considered this before, but it is a bit complicated. In contrast to slashes, not every dot separates path segments, which makes the matching a lot more difficult.
I have a working version of httprouter with this change, but the code is difficult to understand, so I am not sure what I just changed:
https://github.com/gin-gonic/httprouter/commit/2ecb7ac21a43e5f3e7041826e53dc007a102e397
what do you think? what could fail?
I know dots do not separate path segments, but nobody is going to use a parameter name with dots, so in my opinion it makes sense to understand a dot as the end of the parameter name.
See my comment on your commit
Additionally, something like router.Get("/account/:id.:filetype", handler)
could be extremely convenient.
we'd love to have this feature too :+1:
@julienschmidt sorry I just saw your comment in my commit. you are right, this is not trivial
@squirkle well, I would not overload the router that much. if you want the extension just do this:
extension := filepath.Ext(filename)
@manucorporat is it necessary to create an endpoint for each filetype or is it possible to allow a route to accept multiple filetypes?
example: route /report will not match /report.json or /report.csv as it ends searching before it gets to the file extension
I could, however, create multiple routes with all the file extensions desired. Thoughts?
Right now the parameter names end with a slash or the end of the path, how about if the dot also means the end of the parameter?