interceptor

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccessLogComponentName = log.GrpcComponentName + ".accessLog"
)

Variables

View Source
var (
	// ServerField is used in every server-side log statement made through grpc_zap.Can be overwritten before initialization.
	ServerField = zap.String("span.kind", "server")
)

Functions

func DefaultCodeToLevel

func DefaultCodeToLevel(code codes.Code) zapcore.Level

DefaultCodeToLevel is the default implementation of gRPC return codes and interceptor log level for server side.

func HandleRecoverError added in v0.1.0

func HandleRecoverError(ctx context.Context, p any) error

HandleRecoverError return recovery error when grpc occur panic. use the options of recovery interceptor.

the method can use easy in biz code, like :

wg.Go(func() (err error) {
	defer func() {
		if r := recover(); r != nil {
			err = interceptor.HandleRecoverError(ctx, r)
		}
	}()

func JWTFromIncomingContext

func JWTFromIncomingContext(ctx context.Context) (*jwt.Token, bool)

JWTFromIncomingContext extracts the token from the incoming context which `ParseTokenFunc` used default token parser.

func UseContextLogger added in v0.3.0

func UseContextLogger() *log.Logger

UseContextLogger replace the default context logger with grpc context logger.

Types

type AccessLogger added in v0.2.0

type AccessLogger struct {
}

func (AccessLogger) Name added in v0.2.0

func (AccessLogger) Name() string

func (AccessLogger) StreamServerInterceptor added in v0.2.0

func (al AccessLogger) StreamServerInterceptor(cnf *conf.Configuration) grpc.StreamServerInterceptor

StreamServerInterceptor returns a new streaming server interceptors that adds a zap.Logger to the context.

func (AccessLogger) UnaryServerInterceptor added in v0.2.0

func (al AccessLogger) UnaryServerInterceptor(cnf *conf.Configuration) grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a new unary server interceptors that adds a zap.Logger to the context.

type GrpcContextLogger added in v0.1.0

type GrpcContextLogger struct {
}

func NewGrpcContextLogger added in v0.1.0

func NewGrpcContextLogger() *GrpcContextLogger

func (*GrpcContextLogger) LogFields added in v0.1.0

func (g *GrpcContextLogger) LogFields(logger *log.Logger, ctx context.Context, lvl zapcore.Level, msg string, fields []zap.Field)

type Interceptor added in v0.2.0

type Interceptor interface {
	Name() string
	UnaryServerInterceptor(cfg *conf.Configuration) grpc.UnaryServerInterceptor
	StreamServerInterceptor(cfg *conf.Configuration) grpc.StreamServerInterceptor
	UnaryClientInterceptor(cfg *conf.Configuration) grpc.UnaryClientInterceptor
	StreamClientInterceptor(cfg *conf.Configuration) grpc.StreamClientInterceptor
	Shutdown(ctx context.Context) error
}

type JWT

type JWT struct {
}

JWT is the interceptor for JWT.

func (JWT) Name added in v0.2.0

func (JWT) Name() string

Name returns the name of the interceptor.

func (JWT) SteamServerInterceptor added in v0.2.0

func (itcp JWT) SteamServerInterceptor(cfg *conf.Configuration) grpc.StreamServerInterceptor

SteamServerInterceptor jwt ServerInterceptor for stream server.

func (JWT) UnaryServerInterceptor added in v0.2.0

func (itcp JWT) UnaryServerInterceptor(cfg *conf.Configuration) grpc.UnaryServerInterceptor

UnaryServerInterceptor ensures a valid token exists within a request's metadata. If the token is missing or invalid, the interceptor blocks execution of the handler and returns an error. Otherwise, the interceptor invokes the unary handler.

type JWTOptions

type JWTOptions struct {
	auth.JWTOptions `json:",inline" yaml:",inline"`
}

JWTOptions is the options for JWT interceptor.

func NewJWTOptions added in v0.2.0

func NewJWTOptions() *JWTOptions

func (*JWTOptions) Apply

func (mw *JWTOptions) Apply(cfg *conf.Configuration)

type LoggerOptions

type LoggerOptions struct {
	TimestampFormat string `json:"timestampFormat" yaml:"timestampFormat"`
	Format          string `json:"format" yaml:"format"`
	// contains filtered or unexported fields
}

func (*LoggerOptions) Apply

func (o *LoggerOptions) Apply(cnf *conf.Configuration)

Apply set access log from grpc logger

type Recovery added in v0.2.0

type Recovery struct {
}

func (Recovery) Name added in v0.2.0

func (Recovery) Name() string

Name return the name of recovery interceptor

func (Recovery) StreamServerInterceptor added in v0.2.0

func (Recovery) StreamServerInterceptor(cnf *conf.Configuration) grpc.StreamServerInterceptor

StreamServerInterceptor returns a new streaming server interceptor for panic recovery.

func (Recovery) UnaryServerInterceptor added in v0.2.0

func (Recovery) UnaryServerInterceptor(cnf *conf.Configuration) grpc.UnaryServerInterceptor

UnaryServerInterceptor catches panics in processing unary requests and recovers.

type RecoveryOptions

type RecoveryOptions struct {
}

type ValuesExtractor

type ValuesExtractor func(ctx context.Context) ([]string, error)

ValuesExtractor defines a function for extracting values (keys/tokens) from the given context.

type WrappedServerStream

type WrappedServerStream struct {
	grpc.ServerStream
	// WrappedContext is the wrapper's own Context. You can assign it.
	WrappedContext context.Context
}

WrappedServerStream is a thin wrapper around grpc.ServerStream that allows modifying context.

func WrapServerStream

func WrapServerStream(stream grpc.ServerStream) *WrappedServerStream

WrapServerStream returns a ServerStream that has the ability to overwrite context.

func (*WrappedServerStream) Context

func (w *WrappedServerStream) Context() context.Context

Context returns the wrapper's WrappedContext, overwriting the nested grpc.ServerStream.Context()

Jump to

Keyboard shortcuts

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