Documentation ¶
Overview ¶
Package client provides common extensions (middleware) required for production DRPC clients.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Interceptor ¶
type Interceptor interface { // Invoke issues a unary RPC to the remote. Invoke(ctx context.Context, rpc string, enc drpc.Encoding, in, out drpc.Message) error // NewStream starts a stream with the remote. NewStream(ctx context.Context, rpc string, enc drpc.Encoding) (drpc.Stream, error) }
Interceptor defines a simplified version of the `drpcconn.Conn` interface for elements wishing to extend the client's RPC processing functionality using middleware pattern.
type LoggingHook ¶
LoggingHook provides a mechanism to extend a message fields just before is submitted.
type Middleware ¶
type Middleware func(Interceptor) Interceptor
Middleware elements allow to customize and extend the RPC requests processing by the client.
func Logging ¶
func Logging(logger xlog.Logger, hook LoggingHook) Middleware
Logging produce output for the processed RPC requests tagged with standard ECS details by default. Fields can be extended by providing a hook function.
func Metadata ¶
func Metadata(payload map[string]string) Middleware
Metadata middleware adds the provided payload data to the context of every request (unary and stream) before sending it to the server.
func PanicRecovery ¶
func PanicRecovery() Middleware
PanicRecovery allows the client to convert unhandled panic events into an "internal" RPC error. This will prevent the client from crashing if a handler produces a `panic` operation.
func RateLimit ¶
func RateLimit(limit int) Middleware
RateLimit enforce a maximum limit of RPC requests per-second on the client. It is implemented as a `token bucket` instance. More information: https://en.wikipedia.org/wiki/Token_bucket
func Retry ¶
func Retry(limit uint, ll xlog.Logger) Middleware
Retry failed requests up to the `limit` number of attempts specified. Retried errors will be logged as warnings along with details about the specific attempt. Multiple tries introduce an increasingly longer backoff delay to account for transient failures on the remote. The specific delay for each attempt is calculated (in ms) as: `delay * (factor * attempt_number)`.