Skip to content
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

Update priorities.go to accept a context.Context #285

Merged
merged 1 commit into from
Mar 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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