Relative Content

Tag Archive for gohttproutes

Why does r.PathValue() not work for subrouters in Go 1.22?

I’m writing an API with some basic CRUD operations, and I’d like to be able to have my “photos” resource as a sub-resource of my “events” (i.e. requests are made against api/events/photos). I also have a dedicated /api/photos endpoint for whatever else, but I really want to be able to use the URL parameters for the event itself in getting the photos as this seems more sensible to me. However, after some finagling I’ve gotten subrouting to work acceptably, but the r.PathValue("eventId") within my subrouting handler simply returns an empty string.