Skip to content
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: Add Context Support and Improve Readability by jamieaitken #156

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

armando-rodriguez-cko
Copy link
Contributor

feat: Add Context Support and Improve Readability

Description:

This PR introduces WithContext variants for all publicly exposed methods in the Go SDK clients. These changes provide developers with fine-grained control over timeouts and cancellations using Go’s native context.Context. Additionally, method signatures and calls have been refactored for improved readability and consistency.


Key Changes:

Context Support

  • Added WithContext versions of all public methods across SDK clients.
    • Examples: CreateWithContext, GetWithContext, UpdateWithContext, DeleteWithContext, etc.
  • Existing methods now delegate to their WithContext counterparts using context.Background().

Improved Readability

  • Multi-argument method declarations and calls are now split across multiple lines to improve clarity and reduce merge conflicts.

No Functional Changes

  • All updates are fully backward-compatible.
  • Existing integrations will continue to work without any required code changes.

Impact

  • Better Flexibility: Enables context-aware request management (timeouts, cancellations, etc.).
  • Cleaner Code: Easier to read and maintain.
  • No Breaking Changes: All previous methods remain intact.

Testing

  • Ensured all methods compile and work as expected.
  • Verified WithContext versions internally delegate to the correct context-aware HTTP client functions (PostWithContext, GetWithContext, etc.).
  • Manual validation for backward compatibility.

Notes

  • These changes align the SDK with idiomatic Go practices.
  • Recommended to update usage examples and documentation to promote WithContext versions going forward.

* Add Context to HTTP layer

* Add Context to Customers client

* Add Context to Disputes client

* Add Context to Events client

* Add Context to Hosted client

* Add Context to Instruments client

* Add Context to Links client

* Add Context to Payments client

* Add Context to Reconciliation client

* Add Context to Sources client

* Add Context to Tokens client

* Add Context to Webhook client

* Add Context to iDEAL client

* Add Context to Klarna client

* Add Context to SEPA client

* Update tests

* Add Context to NAS Payments

---------

Co-authored-by: Armando Rodríguez <[email protected]>
@armando-rodriguez-cko armando-rodriguez-cko requested a review from a team March 21, 2025 13:13
@armando-rodriguez-cko armando-rodriguez-cko linked an issue Mar 21, 2025 that may be closed by this pull request
1 task
@armando-rodriguez-cko armando-rodriguez-cko force-pushed the beta/context-by-jamieaitken branch 2 times, most recently from d8f7ff2 to 3647be0 Compare March 28, 2025 09:43
@armando-rodriguez-cko armando-rodriguez-cko force-pushed the beta/context-by-jamieaitken branch from 3647be0 to f015738 Compare March 28, 2025 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Adding context.Context to all API methods
2 participants