code: func (s *Server) handleDeregisterMember(reason string, member serf.Member) error {
  	// Do not deregister ourself. This can only happen if the current leader
  	// is leaving. Instead, we should allow a follower to take-over and
  	// deregister us later.
  	if member.Name == s.config.NodeName {
  		s.logger.Printf("[WARN] consul: deregistering self (%s) should be done by follower", s.config.NodeName)
  		return nil
  	}
  
  	// Remove from Raft peers if this was a server
  	if valid, parts := metadata.IsConsulServer(member); valid {
  		if err := s.removeConsulServer(member, parts.Port); err != nil {
  			return err
  		}
  	}
  
  	// Check if the node does not exist
  	state := s.fsm.State()
  	_, node, err := state.GetNode(member.Name)
  	if err != nil {
  		return err
  	}
  	if node == nil {
  		return nil
  	}
  
  	// Deregister the node
  	s.logger.Printf("[INFO] consul: member '%s' %s, deregistering", member.Name, reason)
  	req := structs.DeregisterRequest{
  		Datacenter: s.config.Datacenter,
  		Node:       member.Name,
  	}
  	_, err = s.raftApply(structs.DeregisterRequestType, &req)
  	return err
  }
docs: // handleDeregisterMember is used to deregister a member of a given reason