-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat: add URLParam function to router #259
base: main
Are you sure you want to change the base?
Conversation
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.
Cool 👍
func (r *chiWrapper) URLParam(req *http.Request, name string) string { | ||
return chi.URLParam(req, name) | ||
} |
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 don't get why this needs to be a method on the chiWrapper?
why not make this a freestanding function?
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.
It doesn't have to be, as it doesn't access the chi
instance, but from a functional perspective it felt like the appropriate place. I don't have a strong preference, though. What location do you suggest? router/helpers.go
?
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 feel like it could just be some code like this to reexport it?
const URLParam = chi.URLParam
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 personally prefer having a method that we explicitly implement and which we can customise the behaviour of in the future, if needed.
Is this a blocker for you?
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.
you can replace a reexport with a freestanding function at any point, it will not break anyone except if the signature differs which is the same if it is a function now.
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've often just used chi.URLParam
directly
But that means using |
Good to merge? |
Ouch, sorry! This one fell through the cracks. Unless #259 (comment) is a blocker, this is good to go. I'll wait for that to be clarified and then merge. |
I wanted to define a route like
/route/{param}
and extract the value ofparam
in the handler. I didn't find a built-in way of extracting the value of URL parameters with the router, so this PR adds a function that wraps theURLParam
function fromchi
.Example usage:
Apologies if it's already possible to do this with the router and I completely missed it, in which case feel free to close the PR.