Documentation ¶
Index ¶
- Constants
- Variables
- func CodeFromHTTPStatus(status int) codes.Code
- func Ctx(ctx hexa.Context) context.Context
- func DurationToTimeMillisFormatter(duration time.Duration) hexa.Map
- func Error(status *status.Status) hexa.Error
- func HTTPStatusFromCode(code codes.Code) int
- func MaskMapPaths(m hexa.Map, mask *field_mask.FieldMask, depth int)
- func NewLogger(l hexa.Logger, cfg hexa.Config) grpclog.LoggerV2
- func RecoverHandler(r interface{}) error
- func Status(hexaErr hexa.Error, t hexa.Translator) *status.Status
- type DurationFormatter
- type ErrInterceptorOptions
- type ErrorDetails
- func (*ErrorDetails) Descriptor() ([]byte, []int)
- func (m *ErrorDetails) GetCode() string
- func (m *ErrorDetails) GetData() string
- func (m *ErrorDetails) GetLocalizedMessage() string
- func (m *ErrorDetails) GetStatus() int32
- func (*ErrorDetails) ProtoMessage()
- func (m *ErrorDetails) Reset()
- func (m *ErrorDetails) String() string
- func (m *ErrorDetails) XXX_DiscardUnknown()
- func (m *ErrorDetails) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *ErrorDetails) XXX_Merge(src proto.Message)
- func (m *ErrorDetails) XXX_Size() int
- func (m *ErrorDetails) XXX_Unmarshal(b []byte) error
- type ErrorInterceptor
- type HexaContextInterceptor
- type LoggerOptions
- type RequestLogger
- type Service
Constants ¶
const ContextKeyHexaCtx = "__hexa_ctx__"
ContextKeyHexaCtx is the identifier to set the hexa context as a field in the context of a gRPC method.
const GRPCLogVerbosityLevel = "GRPC_GO_LOG_VERBOSITY_LEVEL"
Config name for log verbosity v
Variables ¶
var (
ErrInvalidHexaContextPayload = status.Error(codes.Internal, "invalid hexa context payload provided to json marshaller")
)
var (
ErrUnknownError = hexa.NewError(http.StatusInternalServerError, "hrpc.u.e.0", hexa.ErrKeyInternalError, nil)
)
Functions ¶
func CodeFromHTTPStatus ¶
CodeFromHTTPStatus converts a https status into corresponding gRPC error code. Note: error mapping from http status to hRPC code is not good, do not use this function as you can.
func DurationToTimeMillisFormatter ¶
DurationToTimeMillisFormatter converts the duration to milliseconds.
func HTTPStatusFromCode ¶
HTTPStatusFromCode converts a gRPC error code into the corresponding HTTP response status. See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto Note: We got this function from the [gRPC gateway](https://github.com/grpc-ecosystem/grpc-gateway/blob/master/runtime/errors.go)
func MaskMapPaths ¶
func MaskMapPaths(m hexa.Map, mask *field_mask.FieldMask, depth int)
MaskMapPaths mask all paths in the provided map with the provided depth.
func RecoverHandler ¶
func RecoverHandler(r interface{}) error
RecoverHandler handle handle recovered data from panics in the gRPC server
Types ¶
type DurationFormatter ¶
DurationFunc get a duration and return formatted duration as key (name of field that should log) and value(formatted time)
type ErrInterceptorOptions ¶
type ErrInterceptorOptions struct { Logger hexa.Logger Translator hexa.Translator ReportErrors bool // report errors ? }
ErrInterceptorOptions is the options
type ErrorDetails ¶
type ErrorDetails struct { // HTTP status Status int32 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // Error code Code string `protobuf:"bytes,2,opt,name=code,proto3" json:"code,omitempty"` // Localized error message LocalizedMessage string `protobuf:"bytes,3,opt,name=localized_message,json=localizedMessage,proto3" json:"localized_message,omitempty"` // json marshalled error data Data string `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
--------------------------------
Hexa error message
-------------------------------- Go Generation command:
func (*ErrorDetails) Descriptor ¶
func (*ErrorDetails) Descriptor() ([]byte, []int)
func (*ErrorDetails) GetCode ¶
func (m *ErrorDetails) GetCode() string
func (*ErrorDetails) GetData ¶
func (m *ErrorDetails) GetData() string
func (*ErrorDetails) GetLocalizedMessage ¶
func (m *ErrorDetails) GetLocalizedMessage() string
func (*ErrorDetails) GetStatus ¶
func (m *ErrorDetails) GetStatus() int32
func (*ErrorDetails) ProtoMessage ¶
func (*ErrorDetails) ProtoMessage()
func (*ErrorDetails) Reset ¶
func (m *ErrorDetails) Reset()
func (*ErrorDetails) String ¶
func (m *ErrorDetails) String() string
func (*ErrorDetails) XXX_DiscardUnknown ¶
func (m *ErrorDetails) XXX_DiscardUnknown()
func (*ErrorDetails) XXX_Marshal ¶
func (m *ErrorDetails) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*ErrorDetails) XXX_Merge ¶
func (m *ErrorDetails) XXX_Merge(src proto.Message)
func (*ErrorDetails) XXX_Size ¶
func (m *ErrorDetails) XXX_Size() int
func (*ErrorDetails) XXX_Unmarshal ¶
func (m *ErrorDetails) XXX_Unmarshal(b []byte) error
type ErrorInterceptor ¶
type ErrorInterceptor struct{}
ErrorInterceptor implements a gRPC interceptor to convert error into status and reverse.
func NewErrorInterceptor ¶
func NewErrorInterceptor() *ErrorInterceptor
NewErrorInterceptor returns new instance of the ErrorInterceptor
func (ErrorInterceptor) UnaryClientInterceptor ¶
func (i ErrorInterceptor) UnaryClientInterceptor() grpc.UnaryClientInterceptor
UnaryClientInterceptor returns client interceptor to convert status to Hexa error. Note: error interceptor must be first client interceptor.
func (ErrorInterceptor) UnaryServerInterceptor ¶
func (i ErrorInterceptor) UnaryServerInterceptor(o ErrInterceptorOptions) grpc.UnaryServerInterceptor
UnaryServerInterceptor returns unary server interceptor to convert Hexa error to status.
type HexaContextInterceptor ¶
type HexaContextInterceptor struct {
// contains filtered or unexported fields
}
HexaContextInterceptor is the gRPC interceptor to pass hexa context through gRPC. Note: we do not provide stream interceptors, if you think need it, create PR or issue.
func NewHexaContextInterceptor ¶
func NewHexaContextInterceptor(cei hexa.ContextExporterImporter) *HexaContextInterceptor
NewHexaContextInterceptor returns new instance of the HexaContextInterceptor.
func (*HexaContextInterceptor) UnaryClientInterceptor ¶
func (ci *HexaContextInterceptor) UnaryClientInterceptor(ctx context.Context, method string, req interface{}, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error
func (*HexaContextInterceptor) UnaryServerInterceptor ¶
func (ci *HexaContextInterceptor) UnaryServerInterceptor(c context.Context, req interface{}, info *grpc.UnaryServerInfo, h grpc.UnaryHandler) (interface{}, error)
type LoggerOptions ¶
type LoggerOptions struct { ErrorToCode grpc_logging.ErrorToCode ShouldLog grpc_logging.Decider DurationFormatter DurationFormatter LogRequest bool LogResponse bool }
func DefaultLoggerOptions ¶
func DefaultLoggerOptions(logRequestResponse bool) LoggerOptions
type RequestLogger ¶
type RequestLogger struct {
// contains filtered or unexported fields
}
RequestLogger implements gRPC interceptor to log each request
func NewRequestLogger ¶
func NewRequestLogger(l hexa.Logger) *RequestLogger
NewRequestLogger returns new instance of the RequestLogger
func (*RequestLogger) UnaryServerInterceptor ¶
func (l *RequestLogger) UnaryServerInterceptor(o LoggerOptions) grpc.UnaryServerInterceptor