Skip to content

feat: Introduce Context #287

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

feat: Introduce Context #287

wants to merge 4 commits into from

Conversation

manisha1997
Copy link
Contributor

Fixes

Introduce Context

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

If you have questions, please file a support ticket, or create a GitHub Issue in this repository.

@manisha1997 manisha1997 linked an issue May 19, 2025 that may be closed by this pull request
@kevinburkesegment
Copy link
Contributor

I'm concerned about the duplication in SendRequest/SendRequestWithContext - it might be better to have SendRequest just call SendRequestWithContext with a context.Background(), and then that way you only have one version of the code.

@@ -220,6 +222,89 @@ func (c *Client) SendRequest(method string, rawURL string, data url.Values,
return c.doWithErr(req)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

OK - I still think we should modify SendRequest to have no method body and just instead call

return SendRequestWithContext(context.Background(), method, rawURL, data, headers, body)

}
if c.OAuth() != nil {
oauth := c.OAuth()
token, _ := c.OAuth().GetAccessToken(context.TODO())
Copy link
Contributor

Choose a reason for hiding this comment

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

Should pass through the context here as well.

@@ -25,13 +26,13 @@ func ReadLimits(pageSize *int, limit *int) int {
}
}

func GetNext(baseUrl string, response interface{}, getNextPage func(nextPageUri string) (interface{}, error)) (interface{}, error) {
func GetNextWithContext(ctx context.Context, baseUrl string, response interface{}, getNextPage func(ctx context.Context, nextPageUri string) (interface{}, error)) (interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to add this as a second method, similar to the SendRequestWithContext, otherwise we're going to break everyone's clients.

}
}

func (c *RequestHandlerWithContext) sendRequest(method string, rawURL string, data url.Values,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think what you want here is to have the first method here be a context.Context and then you can edit the methods below to call this instead.

@@ -22,7 +30,16 @@ func NewRequestHandler(client BaseClient) *RequestHandler {
}
}

func (c *RequestHandler) sendRequest(method string, rawURL string, data url.Values,
func NewRequestHandlerWithContext(client BaseClient) *RequestHandlerWithContext {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure you need a separate struct for this honestly, just add a new method/methods on the RequestHandler and call it from everything.

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