func WithMiddleware(middleware ...func(http.Handler) http.Handler) Option {
	return func(s *Server) error {
		s.middlewares = append(s.middlewares, middleware...)
		return nil
	}
}
WithMiddleware adds the given middleware to the endpoints defined in the http router
package server
import (
	"net/http"
	"strings"
	"sync"
	"time"
	"github.com/gorilla/websocket"
	"github.com/haraqa/haraqa/internal/filequeue"
	"github.com/haraqa/haraqa/internal/headers"
	"github.com/haraqa/haraqa/internal/memconsumer"
	"github.com/haraqa/haraqa/internal/queue"
	"github.com/pkg/errors"
)
type Option func(*Server) error
func WithConsumerManager(consumerManager ConsumerManager) Option {
	return func(s *Server) error {
		if consumerManager == nil {
			return errors.New("consumerManager cannot be nil")
		}
		s.consumerManager = consumerManager
		return nil
	}
}
func WithDistributor(distributor Distributor) Option {
	return func(s *Server) error {
		if distributor == nil {
			return errors.New("distributor cannot be nil")
		}
		s.distributor = distributor
		return nil
	}
}
func WithQueue(q Queue) Option {
	return func(s *Server) error {
		if q == nil {
			return errors.New("queue cannot be nil")
		}
		s.q = q
		return nil
	}
}
func WithFileQueue(dirs []string, cache bool, entries int64) Option {
	return func(s *Server) error {
		if s.q != nil {
			return nil
		}
		if len(dirs) == 0 {
			return errors.New("at least one directory must be given")
		}
		if entries < 0 {
			return errors.New("invalid entries, value must not be negative")
		}
		var err error
		s.q, err = filequeue.New(cache, entries, dirs...)
		return err
	}
}
func WithDefaultQueue(dirs []string, cache bool, entries int64) Option {
	return func(s *Server) error {
		if s.q != nil {
			return nil
		}
		if len(dirs) == 0 {
			return errors.New("at least one directory must be given")
		}
		if entries < 0 {
			return errors.New("invalid entries, value must not be negative")
		}
		var err error
		s.q, err = queue.NewQueue(dirs, cache, entries)
		return err
	}
}
func WithMetrics(metrics Metrics) Option {
	return func(s *Server) error {
		if metrics == nil {
			return errors.New("metrics cannot be nil")
		}
		s.metrics = metrics
		return nil
	}
}
func WithDefaultConsumeLimit(n int64) Option {
	return func(s *Server) error {
		if n <= 0 {
			n = -1
		}
		s.defaultConsumeLimit = n
		return nil
	}
}