-
Notifications
You must be signed in to change notification settings - Fork 41
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
feat: introduce base client that utilizes context #196
Merged
childish-sambino
merged 3 commits into
twilio:main
from
natebrennand:natebrennand/add-context-methods-to-base-client
Nov 8, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
Should this be calling
SendRequestWithCtx
instead? Otherwise the context is swallowed.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.
Sorry, there really should've been a comment over
wrapperClient
to make this more explicit.wrapperClient
is wrapping the olderBaseClient
implementation. So this method is the new interface passing though to the context-free client.This enables the SDK to use the
BaseClientWithCtx
interface everywhere since we can transform the olderBaseClient
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.
Ah, understanding better now the intent. I'm thinking it would be a little easier to understand the implications by actually having the
wrapperClient
send through the provided context (which is what I was expecting in the initial review).wrapping/upgrading is adding the ability to an existing client/handler to pass a context through (by adding an implementation for
SendRequestWithCtx
to it). So it no longer becomes a noop that swallows the context. That way if I wanted to take an existing integration and start adding context to API calls, all I'd need to do is switch to use the context-based version of the API method (no initialization changes needed to the client/service/handler).Thoughts?
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.
So there are a few different ways for folks to instantiate a twiliogo client, in all but one the
*WithCtx
methods will operate as expected. There's just one scenario where it will be misleading to the integration developer, but I think it's the most sophisticated setup so there's the highest likelihood they will identify this.Integrations where the client will "just work" with
*WithCtx
methods:twiliogo.NewRestClient
is upgraded automaticallyclient.Client
that provides a*http.Client
will automatically use the contextThe only scenario where a context may be provided but not used is when the integration is using
client.RequestHandler
and has provided a customBaseClient
. If this is the case, there's no way for the library to pass the context in unless we introduce breaking changes, since the specified client by the integration (which is opaque to the SDK) has no method available to ingest a context.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.
Ah, now I I understand. Thanks for bearing with me.