interceptors

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

interceptor is an internal package used by higher level middlewares. It allows injecting custom code in various places of the gRPC lifecycle.

This particular package is intended for use by other middleware, metric, logging or otherwise. This allows code to be shared between different implementations.

Index

Constants

This section is empty.

Variables

View Source
var EmptyTimer = &zeroTimer{}

Functions

func FullMethod

func FullMethod(service, method string) string

func SplitMethodName

func SplitMethodName(fullMethod string) (string, string)

func StreamClientInterceptor

func StreamClientInterceptor(reportable ClientReportable) grpc.StreamClientInterceptor

StreamClientInterceptor is a gRPC client-side interceptor that provides reporting for Stream RPCs.

func StreamServerInterceptor

func StreamServerInterceptor(reportable ServerReportable) grpc.StreamServerInterceptor

StreamServerInterceptor is a gRPC server-side interceptor that provides reporting for Streaming RPCs.

func UnaryClientInterceptor

func UnaryClientInterceptor(reportable ClientReportable) grpc.UnaryClientInterceptor

UnaryClientInterceptor is a gRPC client-side interceptor that provides reporting for Unary RPCs.

func UnaryServerInterceptor

func UnaryServerInterceptor(reportable ServerReportable) grpc.UnaryServerInterceptor

UnaryServerInterceptor is a gRPC server-side interceptor that provides reporting for Unary RPCs.

Types

type ClientReportable

type ClientReportable interface {
	ClientReporter(ctx context.Context, reqProtoOrNil interface{}, typ GRPCType, service string, method string) (Reporter, context.Context)
}

type GRPCType

type GRPCType string
const (
	Unary        GRPCType = "unary"
	ClientStream GRPCType = "client_stream"
	ServerStream GRPCType = "server_stream"
	BidiStream   GRPCType = "bidi_stream"
)

func StreamRPCType

func StreamRPCType(info *grpc.StreamServerInfo) GRPCType

type NoopReporter

type NoopReporter struct{}

func (NoopReporter) PostCall

func (NoopReporter) PostCall(error, time.Duration)

func (NoopReporter) PostMsgReceive

func (NoopReporter) PostMsgReceive(interface{}, error, time.Duration)

func (NoopReporter) PostMsgSend

func (NoopReporter) PostMsgSend(interface{}, error, time.Duration)

type Reporter

type Reporter interface {
	PostCall(err error, rpcDuration time.Duration)
	PostMsgSend(reqProto interface{}, err error, sendDuration time.Duration)
	PostMsgReceive(replyProto interface{}, err error, recvDuration time.Duration)
}

type ServerReportable

type ServerReportable interface {
	ServerReporter(ctx context.Context, reqProtoOrNil interface{}, typ GRPCType, service string, method string) (Reporter, context.Context)
}

type Timer

type Timer interface {
	ObserveDuration() time.Duration
}

Timer is a helper interface to time functions. Useful for interceptors to record the total time elapsed since completion of a call.

Directories

Path Synopsis
`auth` a generic server-side auth middleware for gRPC.
`auth` a generic server-side auth middleware for gRPC.
logging is a "parent" package for gRPC logging middlewares.
logging is a "parent" package for gRPC logging middlewares.
`ratelimit` a generic server-side ratelimit middleware for gRPC.
`ratelimit` a generic server-side ratelimit middleware for gRPC.
`recovery` are interceptors that recover from gRPC handler panics.
`recovery` are interceptors that recover from gRPC handler panics.
`retry` provides client-side request retry logic for gRPC.
`retry` provides client-side request retry logic for gRPC.
`skip` allow users to skip interceptors in certain condition.
`skip` allow users to skip interceptors in certain condition.
`tags` adds a Tag object to the context that can be used by other middleware to add context about a request.
`tags` adds a Tag object to the context that can be used by other middleware to add context about a request.
`grpc_timeout` are interceptors that timeout for gRPC client calls.
`grpc_timeout` are interceptors that timeout for gRPC client calls.
tracing is a "parent" package for gRPC logging middlewares.
tracing is a "parent" package for gRPC logging middlewares.
`validator` is a generic request contents validator server-side middleware for gRPC.
`validator` is a generic request contents validator server-side middleware for gRPC.

Jump to

Keyboard shortcuts

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