code: func (nc *Conn) connect() error {
  	var returnedErr error
  
  	// Create actual socket connection
  	// For first connect we walk all servers in the pool and try
  	// to connect immediately.
  	nc.mu.Lock()
  	nc.initc = true
  	// The pool may change inside the loop iteration due to INFO protocol.
  	for i := 0; i < len(nc.srvPool); i++ {
  		nc.current = nc.srvPool[i]
  
  		if err := nc.createConn(); err == nil {
  			// This was moved out of processConnectInit() because
  			// that function is now invoked from doReconnect() too.
  			nc.setup()
  
  			err = nc.processConnectInit()
  
  			if err == nil {
  				nc.srvPool[i].didConnect = true
  				nc.srvPool[i].reconnects = 0
  				returnedErr = nil
  				break
  			} else {
  				returnedErr = err
  				nc.mu.Unlock()
  				nc.close(DISCONNECTED, false)
  				nc.mu.Lock()
  				nc.current = nil
  			}
  		} else {
  			// Cancel out default connection refused, will trigger the
  			// No servers error conditional
  			if strings.Contains(err.Error(), "connection refused") {
  				returnedErr = nil
  			}
  		}
  	}
  	nc.initc = false
  	if returnedErr == nil && nc.status != CONNECTED {
  		returnedErr = ErrNoServers
  	}
  	nc.mu.Unlock()
  	return returnedErr
  }
docs: // Main connect function. Will connect to the nats-server