Conversation
| func (r *chiWrapper) URLParam(req *http.Request, name string) string { | ||
| return chi.URLParam(req, name) | ||
| } |
There was a problem hiding this comment.
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.
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.
i feel like it could just be some code like this to reexport it?
const URLParam = chi.URLParamThere was a problem hiding this comment.
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.
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.
mraerino
left a comment
There was a problem hiding this comment.
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 ofparamin 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 theURLParamfunction 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.