(host string, timeout time.Duration)
| 20 | } |
| 21 | |
| 22 | func LookupIPTimeout(host string, timeout time.Duration) []net.IP { |
| 23 | cntx, cancel := context.WithTimeout(context.Background(), timeout) |
| 24 | defer cancel() |
| 25 | var ch = make(chan []net.IP, 1) |
| 26 | go func() { |
| 27 | ch <- LookupIP(host) |
| 28 | }() |
| 29 | select { |
| 30 | case ipAddrs := <-ch: |
| 31 | return ipAddrs |
| 32 | case <-cntx.Done(): |
| 33 | return nil |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | func ResolveTCPAddr(addr string) *net.TCPAddr { |
| 38 | tcpAddr, _ := net.ResolveTCPAddr("tcp", addr) |