From e65df1d280114b02c6001c8c2f32e022c107aafc Mon Sep 17 00:00:00 2001 From: Tim Heckman Date: Thu, 25 Feb 2021 18:12:19 -0800 Subject: [PATCH] Update priorities.go to accept a context.Context Updates #267 --- priorites.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/priorites.go b/priorites.go index 1fec4d93..72e093f3 100644 --- a/priorites.go +++ b/priorites.go @@ -2,7 +2,6 @@ package pagerduty import ( "context" - "encoding/json" ) // PriorityProperty is a single priorty object returned from the Priorities endpoint @@ -17,18 +16,21 @@ type Priorities struct { Priorities []PriorityProperty `json:"priorities"` } -// ListPriorities lists existing priorities +// ListPriorities lists existing priorities. It's recommended to use +// ListPrioritiesWithContext instead. func (c *Client) ListPriorities() (*Priorities, error) { - resp, err := c.get(context.TODO(), "/priorities") + return c.ListPrioritiesWithContext(context.Background()) +} + +// ListPrioritiesWithContext lists existing priorities. +func (c *Client) ListPrioritiesWithContext(ctx context.Context) (*Priorities, error) { + resp, err := c.get(ctx, "/priorities") if err != nil { return nil, err } - // TODO(theckman): make sure we close the resp.Body here - var p Priorities - err = json.NewDecoder(resp.Body).Decode(&p) - if err != nil { + if err := c.decodeJSON(resp, &p); err != nil { return nil, err }