Documentation
¶
Index ¶
Constants ¶
const ( // RequestIDKey is the request context key used to store the request ID. RequestIDKey ctxKey = iota + 1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallSet ¶
type CallSet []*UnaryRPCCall
CallSet is a set of UnaryRPCCalls that provides APIs for simpler usage.
func (CallSet) First ¶
func (cs CallSet) First() (*UnaryRPCCall, error)
First returns the first RPC call in the call set (if exists).
func (CallSet) Successful ¶
Successful filters successful RPC calls and returns them.
type Condition ¶
type Condition interface{}
Condition represents a pre or postcondition. Must be a function with the specified signature.
type LogFunc ¶
type LogFunc func(args ...interface{})
LogFunc is a function that logs the provided message. It is compatible with stdlib logger methods like `log.Print` and `log.Println`.
type RPCCallHistory ¶
type RPCCallHistory struct {
// contains filtered or unexported fields
}
RPCCallHistory lets you have access to the RPC calls made during an RPC lifetime.
func (*RPCCallHistory) Filter ¶
func (h *RPCCallHistory) Filter(serviceName, methodName string) CallSet
Filter returns RPC calls to the given method. serviceName is name the gRPC service, i.e., package.service. methodName is the method name only, without the service name or package name.
type ServerContract ¶
type ServerContract struct {
// contains filtered or unexported fields
}
ServerContract is a contract defined for a gRPC server.
func NewServerContract ¶
func NewServerContract(logFunc LogFunc) *ServerContract
NewServerContract creates a ServerContract that has no contracts registered. It requires a logger function to log the violation of its contracts.
func (*ServerContract) RegisterServiceContract ¶
func (sc *ServerContract) RegisterServiceContract(svcContract *ServiceContract) error
RegisterServiceContract registers a service contract and its RPC contracts to the gRPC server contract. This must be called before invoking UnaryServerInterceptor.
func (*ServerContract) UnaryClientInterceptor ¶
func (sc *ServerContract) UnaryClientInterceptor() grpc.UnaryClientInterceptor
UnaryClientInterceptor returns a new unary client interceptor for monitoring of RPC calls made by the client.
func (*ServerContract) UnaryServerInterceptor ¶
func (sc *ServerContract) UnaryServerInterceptor() grpc.UnaryServerInterceptor
UnaryServerInterceptor returns a new unary server interceptor for monitoring server contracts.
type ServiceContract ¶
type ServiceContract struct { // ServiceName is name the gRPC service, i.e., package.service. ServiceName string // RPCContracts are the contracts defined for RPCs of the service. RPCContracts []*UnaryRPCContract }
ServiceContract is a contract defined for a gRPC service.
type UnaryRPCCall ¶
type UnaryRPCCall struct { // FullMethod is the full RPC method string, i.e., /package.service/method. FullMethod string // Request is the body of the RPC request. Request interface{} // Response is the body of the RPC response. Response interface{} // Error is the error that returned with the RPC response. Error error // Order represents the invocation time of RPCs in ascending order. Order int }
UnaryRPCCall represents an RPC call and its details.
type UnaryRPCContract ¶
type UnaryRPCContract struct { // MethodName is the method name only, without the service name or package name. MethodName string // PreConditions are conditions that must always be true just prior to the execution of the RPC. // Each PreCondition should be a function with the following signature: // `func(req *Request) error`. PreConditions []Condition // PostConditions are conditions that must always be true just after the execution of the RPC. // Each PostCondition should be a function with the following signature: // `func(resp *Response, respErr error, req *Request, calls contracts.RPCCallHistory) error`. PostConditions []Condition }
UnaryRPCContract represents a contract for a unary RPC.