rpc

package
v0.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const InternalTokenMetadataKey = "x-memoh-internal-token"
View Source
const MaxMessageBytes = 16 << 20
View Source
const MetadataAdapterMessage = "adapter_message"

MetadataAdapterMessage is the ErrorInfo metadata key for an adapter's own error text.

View Source
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.

View Source
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

func AppErrorStatus(err error) error

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

func DecodeAppError(err error) error

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 Dial

func Dial(target, secret string) (*grpc.ClientConn, error)

func NewServer

func NewServer(logger *slog.Logger, secret string, opts ...grpc.ServerOption) *grpc.Server

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

func ReasonOf(err error) (string, bool)

ReasonOf returns the ErrorInfo reason of a received envelope, also when err is an error Restored returned.

func Received added in v0.21.0

func Received(err error) error

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

func RecordError(ctx context.Context, err error)

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

func Restored(restored, received error) error

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

func StopGracefully(srv *grpc.Server, done <-chan struct{}, deadline time.Duration)

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

func WithAdapterMessage(sentinel error, message string) error

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.

func (Reason) Status added in v0.21.0

func (r Reason) Status(adapterMessage string) error

Status returns the envelope for r. A non-empty adapterMessage is redacted and carried under MetadataAdapterMessage.

type Reasons added in v0.21.0

type Reasons []Reason

Reasons is the sentinel table of one RPC package.

func (Reasons) Decode added in v0.21.0

func (t Reasons) Decode(err error) error

Decode restores the sentinel registered for the reason of a received envelope. The adapter message, when present, becomes the restored error's text. It returns nil when err carries no envelope or its reason is not in t.

func (Reasons) Lookup added in v0.21.0

func (t Reasons) Lookup(err error) (Reason, bool)

Lookup returns the first entry whose sentinel err matches.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL