ulule/limiter

Create new ContextStore interface

Closed this issue · 1 comments

Since most "Stores" will require an external request, the interface should implement context.Context so that those requests can respect timeouts and cancellations. I'd expect it to look something like this.

// ContextStore is the common interface for limiter stores.
type ContextStore interface {
	Get(ctx context.Context, key string, rate Rate) (Context, error)
	Peek(ctx context.Context, key string, rate Rate) (Context, error)
}

Honestly, it would be great if the whole package went v2 and implemented context as the first parameter everywhere, including the middleware functions.

novln commented

Hello Derek,

A v2 is on it's way, we will add context as first parameter for the Store interface.

Thank you for your feedback :)