Golang惯用方式检测没有此类主机错误

I am using this but it doesn't feel right:

if err, ok := err.(net.Error); ok {
    var message string
    if err.Timeout() {
        message = "Timeout"
    } else if strings.HasSuffix(err.Error(), "no such host") {
        message = "No such host"
    }
}

Is there a more idiomatic way?

I think you can use DNSError type instead of common Error.

err, ok := err.(net.DNSError)

You can check DNS errors with this code. For example if err is our error:

if err, ok := err.(*url.Error); ok {
    if err, ok := err.Err.(*net.OpError); ok {
        if _, ok := err.Err.(*net.DNSError); ok {
            retry(r)
        }
    }
}