Skip to content

feat: Add support for passing a Go Context when making an API request#301

Open
lightster wants to merge 1 commit into
twilio:mainfrom
lightster:add-support-for-go-contexts
Open

feat: Add support for passing a Go Context when making an API request#301
lightster wants to merge 1 commit into
twilio:mainfrom
lightster:add-support-for-go-contexts

Conversation

@lightster

@lightster lightster commented Sep 22, 2025

Copy link
Copy Markdown

Fixes

This PR adds support for passing a Go Context when making an API request. All API methods will now have a matching function for passing a Go Context when make the API request. For example, the Taskrouter Workspaces CreateTask function will now have a corresponding CreateTaskWithContext method that accepts a Go context.Context as its first parameter.

Closes #255. Supersedes #287. Supersedes #290.

Checklist

  • I acknowledge that all my contributions will be made under the project's license
  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the Contribution Guidelines and my PR follows them
  • I have titled the PR appropriately
  • I have updated my branch with the main branch
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation about the functionality in the appropriate .md file
  • I have added inline documentation to the code I modified

Comment thread twilio.go
} else {
defaultClient.SetAccountSid(username)
}
requestHandler = client.NewRequestHandler(defaultClient)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manisha1997 Do you know if this twilio.go file is actually generated by twilio-oai-generator as documented in the file header? If so, could you provide guidance on where in twilio-oai-generator the twilio.go file is generated and how I can run the generation?

I have not been able to figure this out on my own as of yet.

Comment thread client/request_handler.go
Comment on lines +20 to +22
// If the base client supports context, add it to the request handler.
// Otherwise we leave it nil and the base client will be used.
clientWithContext, _ := client.(BaseClientWithContext)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Admittedly this is less than ideal, but it allows us to add Context support without breaking backwards compatibility.

@lightster lightster force-pushed the add-support-for-go-contexts branch from ba65a82 to d7e8c7d Compare September 22, 2025 05:46
@lightster

Copy link
Copy Markdown
Author

Hi @manisha1997 @tiwarishubham635 or anyone else on the Twilio team:

Is there anything we can do to move these changes forward? Obviously there are now conflicts in both of my pull requests. I am open to resolving those and pushing updated changes to be reviewed, but before I do that I want to see if you all will be willing to review and move forward with this change.

I think Go Context support is important to the Go community, and my workplace is considering forking the SDK so we have internal Go Context support in the Twilio SDK. I'd love to avoid that and make sure we can get the community access as well.

Thanks so much,

Matt Light

@tiwarishubham635

Copy link
Copy Markdown
Contributor

Hi! I am no more working with Twilio. Someone from the team will help you. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please reintroduce context.Context

2 participants