84_Go基础_1_52 net error


 1 package main
 2 
 3 import (
 4     "fmt"
 5     "net"
 6 )
 7 
 8 func main() {
 9     addr, err := net.LookupHost("www.baidu.com")
10     fmt.Println(err)
11     if ins, ok := err.(*net.DNSError); ok {
12         if ins.Timeout() {
13             fmt.Println("操作超时。。")
14         } else if ins.Temporary() {
15             fmt.Println("临时性错误。。")
16         } else {
17             fmt.Println("通常错误。。")
18         }
19     }
20     fmt.Println(addr)
21 }

相关