Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewRateLimitedClient ¶
func NewRateLimitedClient(conn *grpc.ClientConn, limiter *rate.Limiter) grpc.ClientConnInterface
NewRateLimitedClient creates a new RateLimitedClient that wraps the provided grpc.ClientConn and uses the provided rate.Limiter to control the rate of outgoing requests. It returns a grpc.ClientConnInterface that can be used wherever a grpc.ClientConn is expected.
Parameters:
- conn: The underlying grpc.ClientConn to wrap. This is typically an instance of grpc.ClientConn created using grpc.NewClient or any custom implementation of grpc.ClientConnInterface.
- limiter: The rate.Limiter to use for controlling the rate of outgoing requests.
func NewRateLimitedTransport ¶
func NewRateLimitedTransport(transport http.RoundTripper, limiter *rate.Limiter) http.RoundTripper
NewRateLimitedTransport creates a new RateLimitedTransport that wraps the provided http.RoundTripper and uses the provided rate.Limiter to control the rate of outgoing requests. It returns an http.RoundTripper that can be used wherever an http.RoundTripper is expected.
Parameters:
- transport: The underlying http.RoundTripper to wrap. This is typically an instance of http.Transport or any custom implementation of http.RoundTripper.
- limiter: The rate.Limiter to use for controlling the rate of outgoing requests.
Types ¶
type RateLimitedClient ¶
type RateLimitedClient struct {
ClientConn *grpc.ClientConn
Limiter *rate.Limiter
}
RateLimitedClient is a wrapper around grpc.ClientConn that adds rate limiting functionality to gRPC calls. It uses a rate.Limiter to control the rate of outgoing requests.
func (*RateLimitedClient) Invoke ¶
func (c *RateLimitedClient) Invoke(ctx context.Context, method string, args interface{}, reply interface{}, opts ...grpc.CallOption) error
Invoke performs a gRPC call on the wrapped grpc.ClientConn, applying rate limiting before making the call. If the rate limit is exceeded, it waits until the limiter allows the request.
func (*RateLimitedClient) NewStream ¶
func (c *RateLimitedClient) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error)
NewStream creates a new stream on the wrapped grpc.ClientConn, applying rate limiting before creating the stream. If the rate limit is exceeded, it waits until the limiter allows the request.
type RateLimitedTransport ¶
type RateLimitedTransport struct {
Transport http.RoundTripper
Limiter *rate.Limiter
}
RateLimitedTransport is a wrapper around http.RoundTripper that adds rate limiting functionality to HTTP requests. It uses a rate.Limiter to control the rate of outgoing requests.