Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultCodeToLevel(code codes.Code) zapcore.Level
- func HandleRecoverError(ctx context.Context, p any) error
- func JWTFromIncomingContext(ctx context.Context) (*jwt.Token, bool)
- func UseContextLogger() *log.Logger
- type AccessLogger
- type GrpcContextLogger
- type Interceptor
- type JWT
- type JWTOptions
- type LoggerOptions
- type Recovery
- type RecoveryOptions
- type ValuesExtractor
- type WrappedServerStream
Constants ¶
const (
AccessLogComponentName = log.GrpcComponentName + ".accessLog"
)
Variables ¶
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 ¶
DefaultCodeToLevel is the default implementation of gRPC return codes and interceptor log level for server side.
func HandleRecoverError ¶ added in v0.1.0
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 ¶
JWTFromIncomingContext extracts the token from the incoming context which `ParseTokenFunc` used default token parser.
func UseContextLogger ¶ added in v0.3.0
UseContextLogger replace the default context logger with grpc context logger.
Types ¶
type AccessLogger ¶ added in v0.2.0
type AccessLogger struct { }
AccessLogger is the interceptor for access log. UnaryServerInterceptor and SteamServerInterceptor will use the same logger.
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
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) 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"` // Exclude is a list of http paths to exclude from JWT auth // // path format must same as info.FullMethod started with "/". Exclude []string `json:"exclude" yaml:"exclude"` }
JWTOptions is the options for JWT interceptor.
func NewJWTOptions ¶ added in v0.2.0
func NewJWTOptions() *JWTOptions
NewJWTOptions constructs a new JWTOptions struct with supplied options.
func (*JWTOptions) Apply ¶
func (mw *JWTOptions) Apply(cfg *conf.Configuration)
type LoggerOptions ¶
type LoggerOptions struct { 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) 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 ¶
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()