How to handle client timeout error?
<p>I am trying to make a HTTP call to a server and am using a 10 second client timeout. The current (incorrect) way of how I am handling it is like this:</p>

<pre><code>package checks

import "net/http"
import "fmt"
import "log"
import "time"
import "strings"

var client = &amp;http.Client{Timeout: 10 * time.Second}

func HttpCheck(url string) (string, error) {
    log.Printf("initiating http get to %s\n", url)
    resp, err := client.Get(url)

    if err != nil {
        if strings.Contains(err.Error(), "Client.Timeout") {
            return "loading", nil
        } else {
            log.Printf("error while getting url : %s\n", err.Error())
            return "", err
        }
    }
    defer resp.Body.Close()
    if resp.StatusCode != 200 {
        log.Printf("got a non 200 response: %d", resp.StatusCode)
        return "", fmt.Errorf("Server returned non 200 status: %d", resp.StatusCode)
    }
    log.Println("all is well, returning a success")
    return "up", nil
}
</code></pre>

<p>The actual error thrown by Go <a href="https://golang.org/src/net/http/transport.go?h=httpError#L1083" rel="nofollow"><code>httpError</code></a> is unexported. </p>

<p>How do I reliably handle a client timeout?</p>