grpctools

package
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StreamClientCtxAugmentingInterceptor

func StreamClientCtxAugmentingInterceptor(f ContextAugmenter) grpc.StreamClientInterceptor

StreamClientLimitingInterceptor returns a new stream server interceptor that augments connection context.

func StreamClientLimitingInterceptor

func StreamClientLimitingInterceptor(limiter ClientLimiter) grpc.StreamClientInterceptor

StreamClientLimitingInterceptor returns a new stream server interceptor that performs rate limiting on the request.

func StreamServerCtxAugmentingInterceptor

func StreamServerCtxAugmentingInterceptor(f ContextAugmenter) grpc.StreamServerInterceptor

StreamServerLimitingInterceptor returns a new stream server interceptor that augments connection context.

func StreamServerLimitingInterceptor

func StreamServerLimitingInterceptor(limiter ServerLimiter) grpc.StreamServerInterceptor

StreamServerLimitingInterceptor returns a new stream server interceptor that performs limiting based on the given context

func UnaryClientCtxAugmentingInterceptor

func UnaryClientCtxAugmentingInterceptor(f ContextAugmenter) grpc.UnaryClientInterceptor

UnaryClientCtxAugmentingInterceptor returns a new unary client interceptor that augments connection context.

func UnaryClientLimitingInterceptor

func UnaryClientLimitingInterceptor(limiter ClientLimiter) grpc.UnaryClientInterceptor

UnaryClientLimitingInterceptor returns a new unary client interceptor that performs request rate limiting.

func UnaryServerCtxAugmentingInterceptor

func UnaryServerCtxAugmentingInterceptor(f ContextAugmenter) grpc.UnaryServerInterceptor

UnaryServerLimitingInterceptor returns a new unary server interceptor that augments connection context.

func UnaryServerLimitingInterceptor

func UnaryServerLimitingInterceptor(limiter ServerLimiter) grpc.UnaryServerInterceptor

UnaryServerLimitingInterceptor returns a new unary server interceptor that performs limiting based on the given context

Types

type ClientLimiter

type ClientLimiter interface {
	// Wait blocks until limiter permits an event to happen.
	// It returns an error if the Context is
	// canceled, or the expected wait time exceeds the Context's Deadline.
	Wait(context.Context) error
}

ClientLimiter defines the interface to perform client-side request rate limiting. You can use golang.org/x/time/rate.Limiter as an implementation of this interface.

type ContextAugmenter

type ContextAugmenter func(context.Context) (context.Context, error)

func JoinContexts

func JoinContexts(aux context.Context) ContextAugmenter

JoinContexts returns a ContextAugmenter that alters the main context to propagate cancellation from the aux context. The returned context uses main as the parent context to inherit attached values.

This helper is used here to propagate done signal from both gRPC stream's context (stream is closed/broken) and main program's context (program needs to stop). Polling should stop when one of this conditions happens so using only one of these two contexts is not good enough.

type ServerLimiter

type ServerLimiter interface {
	// Allow should return true and consume one "limitable event" if the limit has not been exceeded. Otherwise, it returns false and does not count towards the limit
	Allow(ctx context.Context) bool
}

ServerLimiter defines the interface to perform server-side request rate limiting. Inspired by golang.org/x/time/rate.Limiter, but accepts a context

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL