[REQ][Go] Pass r.Context into handlers
Created by: metalmatze
Is your feature request related to a problem? Please describe.
I would like to propagate the request context through all levels of my application, so that I can use consistent request tracing across applications.
Describe the solution you'd like
Right now the generated handlers do not pass along the request or at least the request context. This can easily be fixed by:
func (c *DeploymentApiController) GetCurrentDeployment(w http.ResponseWriter, r *http.Request) {
- result, err := c.service.GetCurrentDeployment()
+ result, err := c.service.GetCurrentDeployment(r.Context)
if err != nil {
w.WriteHeader(500)
return
}
EncodeJSONResponse(result, nil, w)
}
Then all handlers of the services we need to implement have ctx context.Context
as first argument. This should also make it possible for requests to close longer taking requests. If that's possible we could even cancel pretty heavy SQL queries etc.
Describe alternatives you've considered
Didn't really consider an alternative, as this is pretty much what every one in Go does these days.