Documentation ¶
Index ¶
- Variables
- func GetRequestID(ctx context.Context) string
- func WrapServerStream(ss grpc.ServerStream, key, value interface{}) grpc.ServerStream
- type ErrorFactory
- type LoggingConfigFunc
- type LoggingMiddleware
- type PanicErrorFactory
- type RecoverConfigFunc
- type RecoverMiddleware
- type RequestIDConfigFunc
- type RequestIDGenerator
- type RequestIDMiddleware
Constants ¶
This section is empty.
Variables ¶
var TokenRequestID = tokenRequestID("scarf.middleware.request_id")
TokenRequestID is the unique token to which the current request's unique ID is written to the request context.
Functions ¶
func GetRequestID ¶
GetRequestID retrieves the current request's unique ID. If no request ID is registered with this context, the empty string is returned.
func WrapServerStream ¶
func WrapServerStream(ss grpc.ServerStream, key, value interface{}) grpc.ServerStream
Types ¶
type ErrorFactory ¶
type LoggingConfigFunc ¶
type LoggingConfigFunc func(m *LoggingMiddleware)
func WithLoggingClock ¶
func WithLoggingClock(clock glock.Clock) LoggingConfigFunc
type LoggingMiddleware ¶
type LoggingMiddleware struct { Logger nacelle.Logger `service:"logger"` Decorator *logging.Decorator `service:"logger-decorator"` // contains filtered or unexported fields }
func NewLogging ¶
func NewLogging(configs ...LoggingConfigFunc) *LoggingMiddleware
NewLogging creates middleware that logs incoming requests and the status of the response after the request is handled.
func (*LoggingMiddleware) ApplyStream ¶
func (m *LoggingMiddleware) ApplyStream(f grpc.StreamHandler, info *grpc.StreamServerInfo) (grpc.StreamHandler, error)
func (*LoggingMiddleware) ApplyUnary ¶
func (m *LoggingMiddleware) ApplyUnary(f grpc.UnaryHandler, info *grpc.UnaryServerInfo) (grpc.UnaryHandler, error)
func (*LoggingMiddleware) Init ¶
func (m *LoggingMiddleware) Init() error
type PanicErrorFactory ¶
type PanicErrorFactory func(interface{}) error
type RecoverConfigFunc ¶
type RecoverConfigFunc func(m *RecoverMiddleware)
func WithRecoverErrorFactory ¶
func WithRecoverErrorFactory(factory PanicErrorFactory) RecoverConfigFunc
func WithRecoverLogAllGoroutines ¶
func WithRecoverLogAllGoroutines(logAllGoroutines bool) RecoverConfigFunc
func WithRecoverStackBufferSize ¶
func WithRecoverStackBufferSize(stackBufferSize int) RecoverConfigFunc
type RecoverMiddleware ¶
type RecoverMiddleware struct { Logger nacelle.Logger `service:"logger"` Decorator *logging.Decorator `service:"logger-decorator"` // contains filtered or unexported fields }
func NewRecovery ¶
func NewRecovery(configs ...RecoverConfigFunc) *RecoverMiddleware
NewRecovery creates middleware that captures panics from the handler and converts them to gRPC error responses. The value of the panic is logged at error level.
func (*RecoverMiddleware) ApplyStream ¶
func (m *RecoverMiddleware) ApplyStream(f grpc.StreamHandler, info *grpc.StreamServerInfo) (grpc.StreamHandler, error)
func (*RecoverMiddleware) ApplyUnary ¶
func (m *RecoverMiddleware) ApplyUnary(f grpc.UnaryHandler, info *grpc.UnaryServerInfo) (grpc.UnaryHandler, error)
func (*RecoverMiddleware) Init ¶
func (m *RecoverMiddleware) Init() error
type RequestIDConfigFunc ¶
type RequestIDConfigFunc func(m *RequestIDMiddleware)
func WithRequestIDErrorFactory ¶
func WithRequestIDErrorFactory(factory ErrorFactory) RequestIDConfigFunc
func WithRequestIDGenerator ¶
func WithRequestIDGenerator(generator RequestIDGenerator) RequestIDConfigFunc
type RequestIDGenerator ¶
type RequestIDMiddleware ¶
type RequestIDMiddleware struct { Logger nacelle.Logger `service:"logger"` Decorator *logging.Decorator `service:"logger-decorator"` // contains filtered or unexported fields }
func NewRequestID ¶
func NewRequestID(configs ...RequestIDConfigFunc) *RequestIDMiddleware
NewRequestID creates middleware that generates a unique ID for the request. The request ID is added to the context and is made available by the GetRequestID function.
func (*RequestIDMiddleware) ApplyStream ¶
func (m *RequestIDMiddleware) ApplyStream(f grpc.StreamHandler, info *grpc.StreamServerInfo) (grpc.StreamHandler, error)
func (*RequestIDMiddleware) ApplyUnary ¶
func (m *RequestIDMiddleware) ApplyUnary(f grpc.UnaryHandler, info *grpc.UnaryServerInfo) (grpc.UnaryHandler, error)
func (*RequestIDMiddleware) Init ¶
func (m *RequestIDMiddleware) Init() error