Go基础_1_52 net error

Tutorial: Go初级 Category: Go Published: 2026-04-07 13:58:26 Views: 21 Likes: 0 Comments: 0
package main

import (
    "fmt"
    "net"
)

func main() {
    addr, err := net.LookupHost("www.baidu.com")
    fmt.Println(err)
    if ins, ok := err.(*net.DNSError); ok {
        if ins.Timeout() {
            fmt.Println("操作超时。。")
        } else if ins.Temporary() {
            fmt.Println("临时性错误。。")
        } else {
            fmt.Println("通常错误。。")
        }
    }
    fmt.Println(addr)
}