Documentation
¶
Index ¶
- func NewLimiter(ctx context.Context, now func() time.Time, cfg *ratelimitV1.RateLimiterConfig) (ratelimitV1.RateLimiterServiceServer, error)
- func UnaryInterceptor(now func() time.Time, descriptors ...*ratelimitV1.RateLimitDescriptors_Entry) grpc.UnaryClientInterceptor
- type MemRateLimiter
- type NoOpRateLimiter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLimiter ¶
func NewLimiter(ctx context.Context, now func() time.Time, cfg *ratelimitV1.RateLimiterConfig) (ratelimitV1.RateLimiterServiceServer, error)
NewLimiter configures a RateLimitServer server.
func UnaryInterceptor ¶
func UnaryInterceptor(now func() time.Time, descriptors ...*ratelimitV1.RateLimitDescriptors_Entry) grpc.UnaryClientInterceptor
UnaryServerInterceptor returns a new unary server interceptors that adds zap.Logger to the context.
Types ¶
type MemRateLimiter ¶
func NewFixedMemoryRateLimiter ¶
func NewFixedMemoryRateLimiter(ctx context.Context, now func() time.Time, rate int64, period time.Duration) *MemRateLimiter
NewFixedMemoryRateLimiter returns an in-memory limiter that allows rate/period requests e.g. 100/second, 1000/minute.
func NewSlidingMemoryRateLimiter ¶
func NewSlidingMemoryRateLimiter(ctx context.Context, now func() time.Time, usePercent float64) *MemRateLimiter
NewSlidingMemoryRateLimiter returns an in-memory limiter that attempts to use rate limiting reports to define a window size and set the limits to a fair amount given the `usePercent` argument.
func (*MemRateLimiter) Do ¶
func (m *MemRateLimiter) Do(ctx context.Context, req *ratelimitV1.DoRequest) (*ratelimitV1.DoResponse, error)
TODO
func (*MemRateLimiter) Report ¶
func (m *MemRateLimiter) Report(ctx context.Context, req *ratelimitV1.ReportRequest) (*ratelimitV1.ReportResponse, error)
Report updates the rate limiter with relevant information.
type NoOpRateLimiter ¶
type NoOpRateLimiter struct{}
func (*NoOpRateLimiter) Do ¶
func (r *NoOpRateLimiter) Do(ctx context.Context, req *v1.DoRequest) (*v1.DoResponse, error)
func (*NoOpRateLimiter) Report ¶
func (r *NoOpRateLimiter) Report(ctx context.Context, req *v1.ReportRequest) (*v1.ReportResponse, error)
Click to show internal directories.
Click to hide internal directories.