-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Currently, there is no way to pass a context.Context to be used when sending requests.
Proper context.Context propagation is essential for allowing applications to cancel outbound API calls or enforce deadlines. It is a strong convention in the Go ecosystem for functions that perform I/O operations or may block for an extended period to accept a context.Context as their first argument.
I would file a PR to bring this enhancement, but it looks like the files are generated. The code generator needs to be adjusted.
A valid approach could be adding an ExecContext method
// kept for backwards-compatibility
func (t *CreateTrackingRequest) Execute() (*model.CreateTrackingResponse, error) {...}
// new
func (t *CreateTrackingRequest) ExecuteContext(ctx context.Context) (*model.CreateTrackingResponse, error) {
req, err := t.build()
if err != nil {...}
+ req = req.WithContext(ctx)
var data model.CreateTrackingResponse
return &data, t.sender.Do(req, &data)
}or another method on the request builder for attaching context:
client, _ := tracking.New()
req := client.Tracking.
CreateTracking().
+ WithContext(ctx).
BuildBody(params)gstvr and fank
Metadata
Metadata
Assignees
Labels
No labels