interceptors

package
v2.0.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: Apache-2.0 Imports: 7 Imported by: 46

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 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 CallMeta

type CallMeta struct {
	ReqProtoOrNil interface{}
	Typ           GRPCType
	Service       string
	Method        string
}

func (CallMeta) FullMethod

func (c CallMeta) FullMethod() string

type ClientReportable

type ClientReportable interface {
	ClientReporter(context.Context, CallMeta) (Reporter, context.Context)
}

type CommonReportableFunc

type CommonReportableFunc func(ctx context.Context, c CallMeta, isClient bool) (Reporter, context.Context)

CommonReportableFunc helper allows an easy way to implement reporter with common client and server logic.

func (CommonReportableFunc) ClientReporter

func (f CommonReportableFunc) ClientReporter(ctx context.Context, c CallMeta) (Reporter, context.Context)

func (CommonReportableFunc) ServerReporter

func (f CommonReportableFunc) ServerReporter(ctx context.Context, c CallMeta) (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(context.Context, CallMeta) (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
Package auth is a middleware that authenticates incoming gRPC requests.
Package auth is a middleware that authenticates incoming gRPC requests.
Package logging is a "parent" package for gRPC logging middlewares.
Package logging is a "parent" package for gRPC logging middlewares.
Package ratelimit is a middleware that limits the rate of requests.
Package ratelimit is a middleware that limits the rate of requests.
Package recovery is a middleware that recovers from panics and logs the panic message.
Package recovery is a middleware that recovers from panics and logs the panic message.
Package retry provides client-side request retry logic for gRPC.
Package retry provides client-side request retry logic for gRPC.
Package selector
Package selector
Package skip
Package skip
Package timeout is a middleware that responds with a timeout error after the given duration.
Package timeout is a middleware that responds with a timeout error after the given duration.
Package validator
Package validator

Jump to

Keyboard shortcuts

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