From 4d470178bdbc4dfa0518ea4acb97600786d881cd Mon Sep 17 00:00:00 2001 From: Tim Heckman Date: Thu, 25 Feb 2021 18:05:09 -0800 Subject: [PATCH] Update on_call.go to accept a context.Context Updates #267 --- on_call.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/on_call.go b/on_call.go index da59fcd1..2e1ecfe5 100644 --- a/on_call.go +++ b/on_call.go @@ -35,16 +35,28 @@ type ListOnCallOptions struct { Earliest bool `url:"earliest,omitempty"` } -// ListOnCalls list the on-call entries during a given time range. +// ListOnCalls list the on-call entries during a given time range. It's +// recommended to use ListOnCallsWithContext instead. func (c *Client) ListOnCalls(o ListOnCallOptions) (*ListOnCallsResponse, error) { + return c.ListOnCallsWithContext(context.Background(), o) +} + +// ListOnCallsWithContext list the on-call entries during a given time range. +func (c *Client) ListOnCallsWithContext(ctx context.Context, o ListOnCallOptions) (*ListOnCallsResponse, error) { v, err := query.Values(o) if err != nil { return nil, err } - resp, err := c.get(context.TODO(), "/oncalls?"+v.Encode()) + + resp, err := c.get(ctx, "/oncalls?"+v.Encode()) if err != nil { return nil, err } + var result ListOnCallsResponse - return &result, c.decodeJSON(resp, &result) + if err := c.decodeJSON(resp, &result); err != nil { + return nil, err + } + + return &result, nil }