title: How to set timeout while doing a net.DialTCP in golang?
body: <p>As <code>net.DialTCP</code> seems like the only way to get <code>net.TCPConn</code>, I'm not sure how to set timeouts while doing the <code>DialTCP</code>. <a href="https://golang.org/pkg/net/#DialTCP" rel="noreferrer">https://golang.org/pkg/net/#DialTCP</a></p>
  
  <pre><code>func connectAddress(addr *net.TCPAddr, wg *sync.WaitGroup) error {
      start := time.Now()
      conn, err := net.DialTCP("tcp", nil, addr)
      if err != nil {
          log.Printf("Dial failed for address: %s, err: %s", addr.String(), err.Error())
          return err
      }
      elasped := time.Since(start)
      log.Printf("Connected to address: %s in %dms", addr.String(), elasped.Nanoseconds()/1000000)
      conn.Close()
      wg.Done()
      return nil
  }
  </code></pre>