Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REQ][Go] Pass r.Context into handlers #6657

Closed
metalmatze opened this issue Jun 14, 2020 · 4 comments · Fixed by #7214
Closed

[REQ][Go] Pass r.Context into handlers #6657

metalmatze opened this issue Jun 14, 2020 · 4 comments · Fixed by #7214

Comments

@metalmatze
Copy link

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. 😊

@metalmatze metalmatze changed the title [REQ][GO] Pass r.Context into handlers [REQ][Go] Pass r.Context into handlers Jun 14, 2020
@metalmatze
Copy link
Author

metalmatze commented Jun 14, 2020

Ah, I didn't mention that this is for the Go Server and not the client.

@metalmatze
Copy link
Author

Anyone to take a look. I'm happy to work on a PR, but want to know if that's wanted first.

@metalmatze
Copy link
Author

Hey @antihax @bvwells @grokify @kemokemo @bkabrda 😊

@kemokemo
Copy link
Contributor

@metalmatze Thank you for registering the issue. 😄
I feel that this is a very good suggestion indeed. It would be great if you could make a pull request.

ryutah added a commit to ryutah/openapi-generator that referenced this issue Aug 14, 2020
ryutah added a commit to ryutah/openapi-generator that referenced this issue Aug 14, 2020
wing328 pushed a commit that referenced this issue Aug 14, 2020
… http request's context. (#7214)

* adds context arguments to go-server templates (#6657)

* updates go-api-server samples (#6657)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants