interceptors

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: Apache-2.0 Imports: 7 Imported by: 65

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

Functions

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 {
	ReqOrNil any
	Typ      GRPCType
	Service  string
	Method   string
	IsClient bool
}

func NewClientCallMeta

func NewClientCallMeta(fullMethod string, streamDesc *grpc.StreamDesc, reqOrNil any) CallMeta

func NewServerCallMeta

func NewServerCallMeta(fullMethod string, streamInfo *grpc.StreamServerInfo, reqOrNil any) CallMeta

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) (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"
)

type NoopReporter

type NoopReporter struct{}

func (NoopReporter) PostCall

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

func (NoopReporter) PostMsgReceive

func (NoopReporter) PostMsgReceive(any, error, time.Duration)

func (NoopReporter) PostMsgSend

func (NoopReporter) PostMsgSend(any, error, time.Duration)

type Reporter

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

type ServerReportable

type ServerReportable interface {
	ServerReporter(context.Context, CallMeta) (Reporter, context.Context)
}

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 protovalidate is a request validator that uses https://github.com/bufbuild/protovalidate-go under the hood.
Package protovalidate is a request validator that uses https://github.com/bufbuild/protovalidate-go under the hood.
Package ratelimit is a middleware that limits the rate of requests.
Package ratelimit is a middleware that limits the rate of requests.
Package realip is a middleware that extracts the real IP of requests based on header values.
Package realip is a middleware that extracts the real IP of requests based on header values.
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 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