// Returns vulcan library compatible middleware
func (c *ConnLimit) NewHandler(next http.Handler) (http.Handler, error) {
	extract, err := utils.NewExtractor(c.Variable)
	if err != nil {
		return nil, err
	}
	return connlimit.New(next, extract, c.Connections)
}
func NewConnLimit(connections int64, variable string) (*ConnLimit, error) {
	if _, err := utils.NewExtractor(variable); err != nil {
		return nil, err
	}
	if connections < 0 {
		return nil, fmt.Errorf("connections should be > 0, got %d", connections)
	}
	return &ConnLimit{
		Connections: connections,
		Variable:    variable,
	}, nil
}
func FromOther(o RateLimit) (plugin.Middleware, error) {
	if o.Requests <= 0 {
		return nil, fmt.Errorf("requests should be > 0, got %d", o.Requests)
	}
	if o.Burst < 0 {
		return nil, fmt.Errorf("burst should be >= 0, got %d", o.Burst)
	}
	if o.PeriodSeconds <= 0 {
		return nil, fmt.Errorf("period seconds should be > 0, got %d", o.PeriodSeconds)
	}
	extract, err := utils.NewExtractor(o.Variable)
	if err != nil {
		return nil, err
	}
	extractRates, err := makeRateExtractor(o.RateVar)
	if err != nil {
		return nil, err
	}

	o.extract = extract
	o.extractRates = extractRates
	return &o, nil
}