-
Notifications
You must be signed in to change notification settings - Fork 460
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
Add context.Context support #357
Comments
That would be cool. Unfortunately, I think you'd want to be able to supply a Tagging this as "future" for now. |
Also bear in mind that Google App Engine users still only have access to: |
@pjebs That's only for the next few weeks until GAE adds support for 1.8. |
Without knowing the details, I could see this fairly simple implementation: First of all, add it to the common parameters:
Package users then simply adds the context to the parameters they send. To add it to all requests is then simply a matter of adding it to the Call interface of the Backend: req, err := s.NewRequest(method, path, key, "application/x-www-form-urlencoded", body, params)
if err != nil {
return err
}
if params.Context != nil {
req = req.WithContext(params.Context)
}
if err := s.Do(req, v); err != nil {
return err
}
AFAICT this is backwards compatible and allows sending a custom context to each request. It requires Go 1.8 of course. It is not idiomatic, but it doesn't require you to have all calls duplicated like |
Supports the `Context` struct [1] that came in with Go 1.7 on Stripe API requests. This can be used to carry deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes. Fixes #357. [1] https://golang.org/pkg/context/
Good point Klaus! I've added an implementation based on your suggestion in #477. Thanks.
Good news on that front even! |
And actually, if anyone on here would be willing to take a quick look at #477 just to see what they think from an API perspective, it'd be greatly appreciated. I'll hold merging it a few days to see if we can gather a little feedback. |
Supports the `Context` struct [1] that came in with Go 1.7 on Stripe API requests. This can be used to carry deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes. Fixes #357. [1] https://golang.org/pkg/context/
An alternative is to work like database/sql and add Context versions of the methods under a different (but similar) name. That style seems to be more common (and avoids the "don't put Contexts in structs" review comments). |
Yeah, but that would require duplicating all methods on all clients and also do it for the "client-less" functions in each package. A rough estimate is 280 duplicated functions. A |
Supports the `Context` struct [1] that came in with Go 1.7 on Stripe API requests. This can be used to carry deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes. Fixes #357. [1] https://golang.org/pkg/context/
Thanks for your patience everyone! We've released basic support for |
For all the network calls made in this package, it would be nice to be able to use
context.Context
as the first parameter to all the calls, allowing for program control over cancelation deadlines, metrics and all the other good things that come along with it.The text was updated successfully, but these errors were encountered: