add rate limiter

This commit is contained in:
ginuerzh
2022-09-05 22:46:53 +08:00
parent b25f90c55e
commit 5c46613716
8 changed files with 15 additions and 771 deletions

15
limiter/limiter.go Normal file
View File

@ -0,0 +1,15 @@
package limiter
import "context"
type Limiter interface {
// Wait blocks with the requested n and returns the result value,
// the returned value is less or equal to n.
Wait(ctx context.Context, n int) int
Limit() int
}
type RateLimiter interface {
In(key string) Limiter
Out(key string) Limiter
}