-
Notifications
You must be signed in to change notification settings - Fork 705
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
Setting context for all request? #722
Comments
@renom Could you explain your request in detail along with some samples, please? |
@renom Any feedback? |
@jeevatkm thanks for the response. |
Case 1 (now): func DoSomething(ctx context.Context, url1, url2, url3 string) (err error) {
client := resty.New()
_, err = client.R().SetContext(ctx).Get(url1)
if err != nil {
return err
}
_, err = client.R().SetContext(ctx).Get(url2)
if err != nil {
return err
}
_, err = client.R().SetContext(ctx).Get(url3)
if err != nil {
return err
}
return nil
} Case 1 (updated): func DoSomething(ctx context.Context, url1, url2, url3 string) (err error) {
client := resty.New().SetContext(ctx)
_, err = client.R().Get(url1)
if err != nil {
return err
}
_, err = client.R().Get(url2)
if err != nil {
return err
}
_, err = client.R().Get(url3)
if err != nil {
return err
}
return nil
} |
Case 2 (now): func DoSomething(client *resty.Client, ctx context.Context, url1, url2, url3 string) (err error) {
_, err = client.R().SetContext(ctx).Get(url1)
if err != nil {
return err
}
_, err = client.R().SetContext(ctx).Get(url2)
if err != nil {
return err
}
_, err = client.R().SetContext(ctx).Get(url3)
if err != nil {
return err
}
return nil
} Case 2 (updated): func DoSomething(client *resty.Client, url1, url2, url3 string) (err error) {
_, err = client.R().Get(url1)
if err != nil {
return err
}
_, err = client.R().Get(url2)
if err != nil {
return err
}
_, err = client.R().Get(url3)
if err != nil {
return err
}
return nil
} We can still pass the context: err := DoSomething(client.SetContext(ctx), url1, url2, url3) |
@renom Thank you for the code snippets to explain the use case flow. |
Add
client.SetContext
similar toclient.SetHeader
(Client method)The text was updated successfully, but these errors were encountered: