proposal: add path parameter offset to Param
I would like to propose that a field be added to the Param struct (a backwards compatible change according to the Go compatibility promise) that contains the offset of the path parameter in req.URL.Path or req.URL.Rawpath.
This would make normalization much easier. For example, consider the case where given a path /users/Sam which is parsed using the pattern /users/:username we want to redirect to the canonical profile, /user/sam. We could get the path parameter, apply some form of normalization, and then do a string replace on the URL. This works fine here, but what if the username is user and the canonicalization involves replacing the username with the user ID, say, 123, then our string replace might result in the path: /123/123 which is obviously wrong.
Having the offset would allow us to know exactly what part of a path needed to be normalized and replaced.
This would make the param struct look something like this:
type Param struct {
Key string
Value string
Offset int
}Source: julienschmidt/httprouter