Hi,
Thank you very much for this nice library. It fits my use case nicely and allows to apply lots of different restrictions at the same time.
One small gap I see is that it doesn't seem to be possible to apply the extremes of "unlimited" or "completely blocked" when using LimitFunc.
Consider the following usage:
func byCustomerID(customerID int) int {
return customerID
}
func getCustomerLimit(customerID int) Limit {
plan := lookupCustomerPlan(customerID)
if plan.Terminated {
return rate.Blocked
}
if plan.Unlimited {
return rate.Unlimited
}
return plan.Limit
}
limiter := rate.NewLimiterFunc(byCustomerID, getCustomerLimit)
For "unlimited", one could use a workaround with extremely high counts but this'd consume unnecessary memory and is a bit inelegant.
For "completely blocked", one could naively try something like NewLimit(0, time.Second) but this leads to a division by zero.
Therefore, I think it'd be useful to have special limits representing these extremes and allowing to effectively skip the regular rate limit processing when encountered.
Hi,
Thank you very much for this nice library. It fits my use case nicely and allows to apply lots of different restrictions at the same time.
One small gap I see is that it doesn't seem to be possible to apply the extremes of "unlimited" or "completely blocked" when using
LimitFunc.Consider the following usage:
For "unlimited", one could use a workaround with extremely high counts but this'd consume unnecessary memory and is a bit inelegant.
For "completely blocked", one could naively try something like
NewLimit(0, time.Second)but this leads to a division by zero.Therefore, I think it'd be useful to have special limits representing these extremes and allowing to effectively skip the regular rate limit processing when encountered.