-
-
Notifications
You must be signed in to change notification settings - Fork 980
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
Support matching parameters that containing the delimiter #811
Conversation
@pkieltyka @VojtechVitek please have a look! PS: this might require a major version bump but I think it's worth it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @6543. I think this looks great!
It'd be nice to provide a high-level description of the changes. Something like:
Given this route
r.Get("/files/{file}.{ext}", handleFileExt)
and a request to /files/photos.tar.gz
path
chi will now match the longest leftmost parameter first (same as Regex or filepath.Ext()
):
fmt.Println(chi.URLParam(req, "file"))
fmt.Println(chi.URLParam(req, "ext"))
- photos
- tar.gz
+ photos.tar
+ gz
Yes, this can be considered a breaking change. But I'm not sure if it's worth the major version bump.
Anyway, let's see what @pkieltyka has to say
if segmentlen == -1 { | ||
segmentlen = len(xsearch) | ||
} else { | ||
segmentlen += 1 // just keep the old code working |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how the "old code" was exactly :) Can you explain what this does (and why) in the comment?
These failed cases do look bad imho. I think a option per-parameter option to catch a dot is needed. Maybe expose a constraints regex to the user. like rails does: https://prathamesh.tech/2020/06/15/allowing-dots-in-rails-routes/ If that is not possible, maybe some special syntax like |
This is a breaking change, we can consider it for chi v6. |
Closing in favor of #813 |
close #781