Documentation ¶
Index ¶
- Variables
- func ExtractValidationFieldName(field reflect.StructField) string
- type DefaultHandler
- type LogHandler
- type Loggable
- type RecoveryHandler
- type RecoveryHandlerFuncContext
- type ServerStream
- func (l *ServerStream) Context() context.Context
- func (l *ServerStream) RecvMsg(m interface{}) error
- func (l *ServerStream) SendHeader(m metadata.MD) error
- func (l *ServerStream) SendMsg(m interface{}) error
- func (l *ServerStream) SetHeader(m metadata.MD) error
- func (l *ServerStream) SetTrailer(m metadata.MD)
- type SessionHandler
- type TraceHandler
- type TransformHandler
- type Validatable
- type ValidationHandler
- func (h *ValidationHandler) RegisterValidationCtx(tag string, fn validate.FuncCtx, callValidationEvenIfNull ...bool) error
- func (h *ValidationHandler) Stream(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, ...) error
- func (h *ValidationHandler) Unary(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (_ interface{}, err error)
Constants ¶
This section is empty.
Variables ¶
var ( // ClientUnaryTracer intercepts client unary connections ClientUnaryTracer = grpc.WithUnaryInterceptor( otelgrpc.UnaryClientInterceptor()) // ClientStreamTracer intercepts client stream connections ClientStreamTracer = grpc.WithStreamInterceptor( otelgrpc.StreamClientInterceptor()) )
var Defaulter = &DefaultHandler{}
Defaulter is the interceptor that sets the default values of each input and output parameter
var Logger = &LogHandler{}
Logger is the log interceptor
var Recoverer = &RecoveryHandler{}
Recoverer is the recovery interceptor
var Session = &SessionHandler{}
Session injects the session into the request interceptor
var Tracer = &TraceHandler{}
Tracer is the interceptor that sets the default values of each input and output parameter
var Transformer = &TransformHandler{ Molder: mold.New(), }
Transformer is the interceptor that transforms the values of each input and output parameter
var Validator = &ValidationHandler{ Validator: validate.New(), Translator: translator.New(en.New()), }
Validator is the validation interceptor
Functions ¶
func ExtractValidationFieldName ¶
func ExtractValidationFieldName(field reflect.StructField) string
ExtractValidationFieldName returns the validated field name
Types ¶
type DefaultHandler ¶
type DefaultHandler struct{}
DefaultHandler represents a defaulter
func (*DefaultHandler) Stream ¶
func (h *DefaultHandler) Stream(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
Stream does not validate the stream
func (*DefaultHandler) Unary ¶
func (h *DefaultHandler) Unary(ctx context.Context, input interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
Unary does unary validation
type LogHandler ¶
type LogHandler struct{}
LogHandler represents a logger
func (*LogHandler) Stream ¶
func (h *LogHandler) Stream(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
Stream does stream logging
func (*LogHandler) Unary ¶
func (h *LogHandler) Unary(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
Unary does unary logging
type RecoveryHandler ¶
type RecoveryHandler struct {
Handler RecoveryHandlerFuncContext
}
RecoveryHandler represents an interceptor that recovers from panic
func (*RecoveryHandler) Stream ¶
func (h *RecoveryHandler) Stream(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) (err error)
Stream does stream logging
func (*RecoveryHandler) Unary ¶
func (h *RecoveryHandler) Unary(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (_ interface{}, err error)
Unary does unary logging
type RecoveryHandlerFuncContext ¶
RecoveryHandlerFuncContext is a function that recovers from the panic `p` by returning an `error`. The context can be used to extract request scoped metadata and context values.
type ServerStream ¶
type ServerStream struct { Ctx context.Context Stream grpc.ServerStream }
ServerStream defines the server-side behavior of a streaming RPC.
All errors returned from ServerStream methods are compatible with the status package.
func (*ServerStream) Context ¶
func (l *ServerStream) Context() context.Context
Context returns the context for this stream.
func (*ServerStream) RecvMsg ¶
func (l *ServerStream) RecvMsg(m interface{}) error
RecvMsg blocks until it receives a message into m or the stream is done. It returns io.EOF when the client has performed a CloseSend. On any non-EOF error, the stream is aborted and the error contains the RPC status.
It is safe to have a goroutine calling SendMsg and another goroutine calling RecvMsg on the same stream at the same time, but it is not safe to call RecvMsg on the same stream in different goroutines.
func (*ServerStream) SendHeader ¶
func (l *ServerStream) SendHeader(m metadata.MD) error
SendHeader sends the header metadata. The provided md and headers set by SetHeader() will be sent. It fails if called multiple times.
func (*ServerStream) SendMsg ¶
func (l *ServerStream) SendMsg(m interface{}) error
SendMsg sends a message. On error, SendMsg aborts the stream and the error is returned directly.
SendMsg blocks until:
- There is sufficient flow control to schedule m with the transport, or
- The stream is done, or
- The stream breaks.
SendMsg does not wait until the message is received by the client. An untimely stream closure may result in lost messages.
It is safe to have a goroutine calling SendMsg and another goroutine calling RecvMsg on the same stream at the same time, but it is not safe to call SendMsg on the same stream in different goroutines.
func (*ServerStream) SetHeader ¶
func (l *ServerStream) SetHeader(m metadata.MD) error
SetHeader sets the header metadata. It may be called multiple times. When call multiple times, all the provided metadata will be merged. All the metadata will be sent out when one of the following happens:
- ServerStream.SendHeader() is called;
- The first response is sent out;
- An RPC status is sent out (error or success).
func (*ServerStream) SetTrailer ¶
func (l *ServerStream) SetTrailer(m metadata.MD)
SetTrailer sets the trailer metadata which will be sent with the RPC status. When called more than once, all the provided metadata will be merged.
type SessionHandler ¶
type SessionHandler struct{}
SessionHandler represents an interceptor that recovers from panic
func (*SessionHandler) Stream ¶
func (h *SessionHandler) Stream(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
Stream does stream logging
func (*SessionHandler) Unary ¶
func (h *SessionHandler) Unary(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
Unary does unary logging
type TraceHandler ¶
type TraceHandler struct{}
TraceHandler represents a defaulter
func (*TraceHandler) Stream ¶
func (h *TraceHandler) Stream(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
Stream does not validate the stream
func (*TraceHandler) Unary ¶
func (h *TraceHandler) Unary(ctx context.Context, input interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
Unary does unary validation
type TransformHandler ¶
type TransformHandler struct {
Molder *mold.Transformer
}
TransformHandler represents a mold
func (*TransformHandler) Stream ¶
func (h *TransformHandler) Stream(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
Stream does not validate the stream
func (*TransformHandler) Unary ¶
func (h *TransformHandler) Unary(ctx context.Context, input interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
Unary does unary validation
type Validatable ¶
type Validatable interface {
Validate() error
}
Validatable represents a validatable type
type ValidationHandler ¶
type ValidationHandler struct { Validator *validate.Validate Translator *translator.UniversalTranslator }
ValidationHandler represents a logger
func (*ValidationHandler) RegisterValidationCtx ¶
func (h *ValidationHandler) RegisterValidationCtx(tag string, fn validate.FuncCtx, callValidationEvenIfNull ...bool) error
RegisterValidationCtx does the same as RegisterValidation on accepts a FuncCtx validation allowing context.Context validation support.
func (*ValidationHandler) Stream ¶
func (h *ValidationHandler) Stream(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
Stream does not validate the stream
func (*ValidationHandler) Unary ¶
func (h *ValidationHandler) Unary(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (_ interface{}, err error)
Unary does unary validation