code: func (s *StanServer) startRaftNode(hasStreamingState bool) error {
  	if err := s.createServerRaftNode(hasStreamingState); err != nil {
  		return err
  	}
  	node := s.raft
  
  	leaderWait := make(chan struct{}, 1)
  	leaderReady := func() {
  		select {
  		case leaderWait <- struct{}{}:
  		default:
  		}
  	}
  	if node.State() != raft.Leader {
  		leaderReady()
  	}
  
  	s.wg.Add(1)
  	go func() {
  		defer s.wg.Done()
  		for {
  			select {
  			case isLeader := <-node.notifyCh:
  				if isLeader {
  					err := s.leadershipAcquired()
  					leaderReady()
  					if err != nil {
  						s.log.Errorf("Error on leadership acquired: %v", err)
  						switch {
  						case err == raft.ErrRaftShutdown:
  							// Node shutdown, just return.
  							return
  						case err == raft.ErrLeadershipLost:
  						case err == raft.ErrNotLeader:
  							// Node lost leadership, continue loop.
  							continue
  						default:
  							// TODO: probably step down as leader?
  							panic(err)
  						}
  					}
  				} else {
  					s.leadershipLost()
  				}
  			case <-s.shutdownCh:
  				// Signal channel here to handle edge case where we might
  				// otherwise block forever on the channel when shutdown.
  				leaderReady()
  				return
  			}
  		}
  	}()
  
  	<-leaderWait
  	return nil
  }
docs: // startRaftNode creates and starts the Raft group.
  // This should only be called if the server is running in clustered mode.