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

Commit

Permalink
Rename cx to ctx and create Request with Context directly
Browse files Browse the repository at this point in the history
  • Loading branch information
corny committed Jul 4, 2020
1 parent 17393b4 commit 0e89aa6
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ func interfaceToString(val interface{}) string {
return fmt.Sprintf("%v", val)
}

func (c *Client) httpGet(cx context.Context, url string) (*http.Response, error) {
req, err := http.NewRequest("GET", url, nil)
func (c *Client) httpGet(ctx context.Context, url string) (*http.Response, error) {
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
if err != nil {
return nil, err
}
req = req.WithContext(cx)

// Youtube responses depend on language and user agent
req.Header.Set("Accept-Language", "en-US,en;q=0.5")
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0")

return c.HTTPClient.Do(req)
}

func (c *Client) httpGetAndCheckResponse(cx context.Context, url string) (*http.Response, error) {
func (c *Client) httpGetAndCheckResponse(ctx context.Context, url string) (*http.Response, error) {
c.Logger.Debug().Msgf("Fetching %v", url)

resp, err := c.httpGet(cx, url)
resp, err := c.httpGet(ctx, url)
if err != nil {
return nil, err
}
Expand All @@ -51,8 +51,8 @@ func (c *Client) httpGetAndCheckResponse(cx context.Context, url string) (*http.
return resp, nil
}

func (c *Client) httpGetAndCheckResponseReadBody(cx context.Context, url string) ([]byte, error) {
resp, err := c.httpGetAndCheckResponse(cx, url)
func (c *Client) httpGetAndCheckResponseReadBody(ctx context.Context, url string) ([]byte, error) {
resp, err := c.httpGetAndCheckResponse(ctx, url)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 0e89aa6

Please sign in to comment.