I realize this probably belongs at StackOverflow, but I wonder if there is a cool 'chi' solution rather than a 'Go' solution, so I hope you don't mind me asking here..
Imagine you're building an image serving backend, where you can specify different parameters, such as:
example.com/Jd8saD.jpg?width=420&height=320&fit=crop&rotate=90
Each of these parameters (which could be included in any order) calls different functions to process the image. What would be the best way to go about doing this? Maybe use a single GET function like this:
function ImageGET(w http.ResponseWriter, r *http.Request) {
if r.URL.Query().Get("width") != "" {
// do something
}
if r.URL.Query().Get("height") != "" {
// do something
}
if r.URL.Query().Get("crop") != "" {
// do something
}
etc
}
?
By the way, is it even possible to check for this route? I know I could do:
r.Get("/:image", ImageGET)
but if I do that, then I assume there might be some conflicts with the other routes?
Have a look at http://github.com/pressly/imgry
For those looking for the same thing few years later, you can use if chi.URLParam(r, "width") != "" ...
Most helpful comment
Have a look at http://github.com/pressly/imgry