Skip to content

Commit

Permalink
Merge pull request #285 from PagerDuty/ctx_priorities
Browse files Browse the repository at this point in the history
Update priorities.go to accept a context.Context
  • Loading branch information
Scott McAllister authored Mar 10, 2021
2 parents 1d7e4dd + e65df1d commit 1de0ea6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions priorites.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pagerduty

import (
"context"
"encoding/json"
)

// PriorityProperty is a single priorty object returned from the Priorities endpoint
Expand All @@ -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
}

Expand Down

0 comments on commit 1de0ea6

Please sign in to comment.