title: Go http client timeout vs context timeout
body: <p>What's the difference between timeout set in http.Client and timeout set in request's context?</p>
  <p>I've seen 2 ways of setting timeout in http client.</p>
  <p>First:</p>
  <pre><code>ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
  defer cancel()
  req, err := http.NewRequestWithContext(ctx, http.MethodGet, &quot;http://localhost:8080&quot;, nil)
  </code></pre>
  <p>Second:</p>
  <pre><code>client := http.Client{
      Timeout: 2 * time.Second,
  }
  resp, err := client.Do(req)
  if err != nil {
      panic(err)
  }
  </code></pre>
  <p>when to use one over the other?</p>