-
Notifications
You must be signed in to change notification settings - Fork 470
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
Support Context on API requests #477
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brandur-stripe That looks mostly good to me. This is a bit beyond what I know of Go though and I am not sure I would see edge-case if you missed something.
Is it something we could ask the community to help review? Especially the ones in the original issue reported?
@@ -12,7 +13,7 @@ import ( | |||
. "github.com/stripe/stripe-go/testing" | |||
) | |||
|
|||
func TestCheckinUseBearerAuth(t *testing.T) { | |||
func TestBearerAuth(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opportunistic fix here. "Checkin"'s been stripped everywhere else.
Good point. I asked in the other thread; hopefully we can get some volunteers! |
The test here is pretty simple, so it might be nice to do a Overall, this is a very elegant way to add |
7562d55
to
d6b3d79
Compare
Thanks @derekperkins!
I added a new test in d6b3d79. I avoided
Can you run this by me one more time? I'm not sure I follow. Reusing a context isn't going to persist headers or anything is it? |
I wasn't sure if you had a mock of some kind that would allow you to add a pre-defined delay to get repeatable results.
No, context won't persist anything that you don't want it to. Before context, there was always the possibility of a network error or something that would cause acknowledgment to fail, hence the idempotency key. With context, there is generally going to be a timeout, increasing the likelihood that the user thinks a transaction failed when it actually went through on the server. The suggestion to require the two together was mostly tongue in cheek, but I wouldn't ever use it without the idempotency key. |
params.go
Outdated
// Context used for request. It may carry deadlines, cancelation signals, | ||
// and other request-scoped values across API boundaries and between | ||
// processes. | ||
Context context.Context `form:"-"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know we aren't dealing with newbie programmers, but maybe explicitly stating something like:
// A cancelled or timed out context does not provide any guarantee
// whether the operation was or was not completed on the backend.
// You must still perform appropriate rollback or retry with the same idempotency key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
provide any type guarantee
should either read provide any guarantee
or provide any type of guarantee
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it. I tweaked your comment a bit and committed in 1127516.
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/
d6b3d79
to
1127516
Compare
@derekperkins Ah I see now. Thank you! I actually really like the idea of checking for an idempotency key as well before You're right in that an idempotency key is almost certainly nearly always desirable, but there are a few cases where you can legitimately get away without one like on any type of non-modification request (e.g. say you're retrieving a list or something). I still want to rework how idempotency works in this library a bit (it should probably send an idempotency key by default if one was not specified for example), and I might revisit the decision at that time. |
Supports the
Context
struct [1] that came in with Go 1.7 on Stripe APIrequests. This can be used to carry deadlines, cancelation signals, and
other request-scoped values across API boundaries and between processes.
Fixes #357.
r? @remi-stripe
[1] https://golang.org/pkg/context/