Documentation
¶
Overview ¶
Package middleware defines interfaces that can be implemented by third-party code to intercept RPC method invocations, both on the server-side and client-side.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ServerChain ¶
type ServerChain []ServerInterceptor
ServerChain is a ServerInterceptor that chains multiple interceptors to be applied sequentially.
func (ServerChain) InterceptUnaryRPC ¶
func (c ServerChain) InterceptUnaryRPC( ctx context.Context, info UnaryServerInfo, in proto.Message, next func(ctx context.Context) (out proto.Message, err error), ) (proto.Message, error)
InterceptUnaryRPC is called before the RPC method is invoked.
It must call next() to forward the call to the next interceptor in the chain, or ultimately to the application-defined server implementation.
It returns the output that should be sent to the client.
The RPC input message may be mutated in place. The output message returned by next() must not be modified. To produce different RPC output, return a new output message or error.
type ServerInterceptor ¶
type ServerInterceptor interface { // InterceptUnaryRPC is called before the RPC method is invoked. // // It must call next() to forward the call to the next interceptor in the // chain, or ultimately to the application-defined server implementation. // // It returns the output that should be sent to the client. // // The RPC input message may be mutated in place. The output message // returned by next() must not be modified. To produce different RPC output, // return a new output message or error. InterceptUnaryRPC( ctx context.Context, info UnaryServerInfo, in proto.Message, next func(ctx context.Context) (out proto.Message, err error), ) (proto.Message, error) }
ServerInterceptor is an interface intercepting RPC method calls on the server-side. server.
type UnaryServerInfo ¶
type UnaryServerInfo struct { // Package is the name of the Protocol Buffers package that contains the // service definition. Package string // Service is the name of the RPC service. Service string // Method is the name of the RPC method being invoked. Method string }
UnaryServerInfo encapsulates information about a call to unary RPC method and makes it available to a ServerInterceptor implementation.
type ValidatableMessage ¶
type ValidatableMessage interface { proto.Message // Validate returns an error if the message is invalid. // // The error message may be sent to the RPC client, and as such should not // contain any sensitive information. Validate() error }
ValidatableMessage is an RPC input or output message that provides its own validation.
type Validator ¶
type Validator struct{}
Validator is an implementation of ServerInterceptor that validates RPC input and messages by calling their Validate() method, if present.
The Validator interceptor is installed by default.
func (Validator) InterceptUnaryRPC ¶
func (Validator) InterceptUnaryRPC( ctx context.Context, info UnaryServerInfo, in proto.Message, next func(ctx context.Context) (out proto.Message, err error), ) (proto.Message, error)
InterceptUnaryRPC returns an error if any RPC input or output message that implements ValidatableMessage is invalid.