Documentation
¶
Index ¶
- Constants
- func AppErrorStatus(err error) error
- func DecodeAppError(err error) error
- func Dial(target, secret string) (*grpc.ClientConn, error)
- func NewServer(logger *slog.Logger, secret string, opts ...grpc.ServerOption) *grpc.Server
- func ReasonOf(err error) (string, bool)
- func Received(err error) error
- func RecordError(ctx context.Context, err error)
- func Restored(restored, received error) error
- func StopGracefully(srv *grpc.Server, done <-chan struct{}, deadline time.Duration)
- func StreamClientAuth(secret string) grpc.StreamClientInterceptor
- func StreamClientRequestID(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, ...) (grpc.ClientStream, error)
- func StreamServerAuth(secret string) grpc.StreamServerInterceptor
- func StreamServerRequestID(srv any, stream grpc.ServerStream, _ *grpc.StreamServerInfo, ...) error
- func StreamServerResult(logger *slog.Logger) grpc.StreamServerInterceptor
- func UnaryClientAuth(secret string) grpc.UnaryClientInterceptor
- func UnaryClientRequestID(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, ...) error
- func UnaryServerAuth(secret string) grpc.UnaryServerInterceptor
- func UnaryServerRequestID(ctx context.Context, req any, _ *grpc.UnaryServerInfo, ...) (any, error)
- func UnaryServerResult(logger *slog.Logger) grpc.UnaryServerInterceptor
- func WithAdapterMessage(sentinel error, message string) error
- type Reason
- type Reasons
Constants ¶
const InternalTokenMetadataKey = "x-memoh-internal-token"
const MaxMessageBytes = 16 << 20
const MetadataAdapterMessage = "adapter_message"
MetadataAdapterMessage is the ErrorInfo metadata key for an adapter's own error text.
const MetadataFault = "fault"
MetadataFault is the ErrorInfo metadata key for the fault the server attributes the failure to. The client's diagnostics read it as the remote fault; a status without it, from a server that predates it, is attributed as a dependency failure.
const RequestIDMetadataKey = "x-request-id"
RequestIDMetadataKey carries the caller's request id, so that what the callee logs for a call reports the id of the work that made it.
Variables ¶
This section is empty.
Functions ¶
func AppErrorStatus ¶ added in v0.21.0
AppErrorStatus returns the envelope for an apperror whose code is in the catalog: the code is the reason, the catalog detail is the message, and the metadata holds the args and the fault this process attributes err to. It returns nil for any other error.
func DecodeAppError ¶ added in v0.21.0
DecodeAppError restores the apperror of a received envelope whose reason is a catalog code, with the catalog args from its metadata. The fault stays on the received status, where diagnostics read it. It returns nil otherwise.
func NewServer ¶
NewServer builds an internal RPC server. Every call, including one refused by authentication, gets one result line on logger.
func ReasonOf ¶ added in v0.21.0
ReasonOf returns the ErrorInfo reason of a received envelope, also when err is an error Restored returned.
func Received ¶ added in v0.21.0
Received returns the status an RPC client received, from an error Restored returned; any other error is returned unchanged.
func RecordError ¶ added in v0.21.0
RecordError hands err to the RPC result line. A handler calls it when it maps a failure to a status that no longer carries the cause, so that the record still attributes the original error. Outside an RPC it does nothing.
func Restored ¶ added in v0.21.0
Restored is what an RPC client returns for a failure it restored from the received status. It reads as the restored error. Its chain holds the restored error and the received status under one remote marker, so errors.Is and errors.As find the restored value and diagnostics read the status.
func StopGracefully ¶
StopGracefully drains srv but falls back to a hard stop when the context expires or the drain deadline passes — a long-lived Run stream with an active turn would otherwise block shutdown until fx kills the process.
func StreamClientAuth ¶
func StreamClientAuth(secret string) grpc.StreamClientInterceptor
func StreamClientRequestID ¶ added in v0.21.0
func StreamClientRequestID(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error)
func StreamServerAuth ¶
func StreamServerAuth(secret string) grpc.StreamServerInterceptor
func StreamServerRequestID ¶ added in v0.21.0
func StreamServerRequestID(srv any, stream grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error
func StreamServerResult ¶ added in v0.21.0
func StreamServerResult(logger *slog.Logger) grpc.StreamServerInterceptor
StreamServerResult is the streaming counterpart of UnaryServerResult. One stream is one unit of work and gets one result line.
func UnaryClientAuth ¶
func UnaryClientAuth(secret string) grpc.UnaryClientInterceptor
func UnaryClientRequestID ¶ added in v0.21.0
func UnaryClientRequestID(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error
func UnaryServerAuth ¶
func UnaryServerAuth(secret string) grpc.UnaryServerInterceptor
func UnaryServerRequestID ¶ added in v0.21.0
func UnaryServerRequestID(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error)
UnaryServerRequestID puts the caller's request id into the call context. It runs before the result interceptor so the result line reports it.
func UnaryServerResult ¶ added in v0.21.0
func UnaryServerResult(logger *slog.Logger) grpc.UnaryServerInterceptor
UnaryServerResult writes the one result line of each unary call. A handler panic is recorded and then propagated unchanged.
func WithAdapterMessage ¶ added in v0.21.0
WithAdapterMessage returns an error that reads as message and matches sentinel under errors.Is. An empty message returns sentinel.
Types ¶
type Reason ¶ added in v0.21.0
type Reason struct {
// Err is the sentinel. A client restores it so that errors.Is holds.
Err error
// Reason is the ErrorInfo reason. It is stable across releases.
Reason string
// Code is the status code.
Code codes.Code
// Message is the fixed English status message.
Message string
}
Reason registers one sentinel of an RPC package on the wire.
type Reasons ¶ added in v0.21.0
type Reasons []Reason
Reasons is the sentinel table of one RPC package.