(addr string, timeout time.Duration)
| 40 | } |
| 41 | |
| 42 | func ResolveTCPAddrTimeout(addr string, timeout time.Duration) *net.TCPAddr { |
| 43 | cntx, cancel := context.WithTimeout(context.Background(), timeout) |
| 44 | defer cancel() |
| 45 | var ch = make(chan *net.TCPAddr, 1) |
| 46 | go func() { |
| 47 | ch <- ResolveTCPAddr(addr) |
| 48 | }() |
| 49 | select { |
| 50 | case tcpAddr := <-ch: |
| 51 | return tcpAddr |
| 52 | case <-cntx.Done(): |
| 53 | return nil |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | var ( |
| 58 | Hostname, _ = os.Hostname() |