Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is an initial effort to introduce Go contexts.
This is something I've been planning for quite a long time. An initial request along with a great PR was provided in #82.
I went back and forth about the idea of merging #82 vs making more structural changes. The main benefit of #82 were:
The downside were mostly two, related to performances and long-term maintainability:
Given that we're not 1.0 yet, I decided to give it a try to use per-request contexts. As mentioned, this is what most clients are moving towards, at least by looking at some quite relevant Go SDKs.
For instance, Cloudflare client is using contexts in new functions. Interestingly, they also have several context-specific methods like
ListZonesContext
, probably because they have to support both for legacy purposes. That's what I'd like to avoid long terms by eating the bullet sooner rather than later.Another client that I often observe is github-go, which had some notable influence to our clients. They made a drastic switch google/go-github@23d6cb9 and they call it done. Same story, they went for per-function context.
So here's the changes I made in this PR:
NewRequest
andDo
are now not exported. This ensures we are free to move things internally without affecting customers outside. I originally kept these names public as I was inspired by go-github, but also because I used them as helpers to test not implemented methods in the context of the client. So I decided to provide a more high levelRequest
method that can be used for this purpose, without allowing anymore to interact with the low-level client internals anymore.newRequest
andDo -> request
around to segment the request preparation. It made it easier to test it, also it required minimum changes in our test suite.