Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #49 from pingles/master
Browse files Browse the repository at this point in the history
Pass context.Context to net/http client
  • Loading branch information
ericchiang committed May 16, 2017
2 parents 929412d + 33e4a6f commit 68b0248
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ type Client struct {
Client *http.Client
}

func (c *Client) newRequest(verb, url string, body io.Reader) (*http.Request, error) {
func (c *Client) newRequest(ctx context.Context, verb, url string, body io.Reader) (*http.Request, error) {
req, err := http.NewRequest(verb, url, body)
if err != nil {
return nil, err
Expand All @@ -117,7 +117,7 @@ func (c *Client) newRequest(verb, url string, body io.Reader) (*http.Request, er
return nil, err
}
}
return req, nil
return req.WithContext(ctx), nil
}

// Option represents optional call parameters, such as label selectors.
Expand Down Expand Up @@ -438,7 +438,7 @@ func (c *Client) create(ctx context.Context, codec *codec, verb, url string, req
return err
}

r, err := c.newRequest(verb, url, bytes.NewReader(body))
r, err := c.newRequest(ctx, verb, url, bytes.NewReader(body))
if err != nil {
return err
}
Expand All @@ -463,7 +463,7 @@ func (c *Client) create(ctx context.Context, codec *codec, verb, url string, req
}

func (c *Client) delete(ctx context.Context, codec *codec, url string) error {
r, err := c.newRequest("DELETE", url, nil)
r, err := c.newRequest(ctx, "DELETE", url, nil)
if err != nil {
return err
}
Expand All @@ -488,7 +488,7 @@ func (c *Client) delete(ctx context.Context, codec *codec, url string) error {

// get can be used to either get or list a given resource.
func (c *Client) get(ctx context.Context, codec *codec, url string, resp interface{}) error {
r, err := c.newRequest("GET", url, nil)
r, err := c.newRequest(ctx, "GET", url, nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -574,7 +574,7 @@ func (c *Client) watch(ctx context.Context, url string) (*watcher, error) {
} else {
url = url + "?watch=true"
}
r, err := c.newRequest("GET", url, nil)
r, err := c.newRequest(ctx, "GET", url, nil)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 68b0248

Please sign in to comment.