Documentation
¶
Overview ¶
go/grpc/middleware/errors.go
Index ¶
- Variables
- func AppendToOutgoingContextWithPropagation(ctx context.Context, key, value string, opts ...PropagateOption) context.Context
- func AppendTrailer(ctx context.Context, key string, values ...string) bool
- func AppendTrailerWithPropagation(ctx context.Context, key string, values ...string) bool
- func GetFields(ctx context.Context) ([]any, bool)
- func InjectLogFields(ctx context.Context, args ...any) bool
- func MethodDescriptorFromContext(ctx context.Context) (protoreflect.MethodDescriptor, bool)
- func MustParseFullMethod(fullMethod string) (service, method string)
- func RegisterHookHandler[T proto.Message](handler HookHandler[T], opts ...HookOption) error
- func StreamClientRetry() grpc.StreamClientInterceptor
- func StreamClientTrailerPropagation() grpc.StreamClientInterceptor
- func StreamServerAIPLogging() grpc.StreamServerInterceptor
- func StreamServerCanonicalize() grpc.StreamServerInterceptor
- func StreamServerDebugInfoScrubber() grpc.StreamServerInterceptor
- func StreamServerErrorInfoInjector() grpc.StreamServerInterceptor
- func StreamServerFieldMask() grpc.StreamServerInterceptor
- func StreamServerHeaderPropagation() grpc.StreamServerInterceptor
- func StreamServerHook() grpc.StreamServerInterceptor
- func StreamServerLogContextTagInitializer() grpc.StreamServerInterceptor
- func StreamServerLogging(logger *slog.Logger) grpc.StreamServerInterceptor
- func StreamServerMethodDescriptor() grpc.StreamServerInterceptor
- func StreamServerTrailerPropagation() grpc.StreamServerInterceptor
- func StreamServerValidate(validator protovalidate.Validator) grpc.StreamServerInterceptor
- func UnaryClientRetry() grpc.UnaryClientInterceptor
- func UnaryClientTimeout() grpc.UnaryClientInterceptor
- func UnaryClientTrailerPropagation() grpc.UnaryClientInterceptor
- func UnaryClientValidate(validator protovalidate.Validator) grpc.UnaryClientInterceptor
- func UnaryServerAIPLogging() grpc.UnaryServerInterceptor
- func UnaryServerCanonicalize() grpc.UnaryServerInterceptor
- func UnaryServerDebugInfoScrubber() grpc.UnaryServerInterceptor
- func UnaryServerErrorInfoInjector() grpc.UnaryServerInterceptor
- func UnaryServerFieldMask() grpc.UnaryServerInterceptor
- func UnaryServerHeaderPropagation() grpc.UnaryServerInterceptor
- func UnaryServerHook() grpc.UnaryServerInterceptor
- func UnaryServerLogContextTagInitializer() grpc.UnaryServerInterceptor
- func UnaryServerLogging(logger *slog.Logger) grpc.UnaryServerInterceptor
- func UnaryServerMethodDescriptor() grpc.UnaryServerInterceptor
- func UnaryServerTrailerPropagation() grpc.UnaryServerInterceptor
- func UnaryServerValidate(validator protovalidate.Validator) grpc.UnaryServerInterceptor
- func WithFieldMask(ctx context.Context, paths string) context.Context
- func WithFieldMaskStrict(ctx context.Context, paths string) context.Context
- func WithReadMask(ctx context.Context, paths string) context.Context
- func WithReadMaskStrict(ctx context.Context, paths string) context.Context
- type HookHandler
- type HookMatcher
- type HookOption
- type PropagateOption
Constants ¶
This section is empty.
Variables ¶
var ( AllButHealth = selector.MatchFunc(func(ctx context.Context, callMeta interceptors.CallMeta) bool { return grpc_health_v1.Health_ServiceDesc.ServiceName != callMeta.Service }) )
Functions ¶
func AppendTrailer ¶
Inject a trailer into the context. Returns false if the context tag is not found.
func AppendTrailerWithPropagation ¶
Use this method if you want to add a trailer to be propagated up the chain of calls.
func InjectLogFields ¶
Inject fields onto the log context tag.
func MethodDescriptorFromContext ¶
func MethodDescriptorFromContext(ctx context.Context) (protoreflect.MethodDescriptor, bool)
func MustParseFullMethod ¶
MustParseFullMethod splits a gRPC full method name "/package.Service/Method" into its service and method parts, panicking if it is malformed.
Use this for names supplied by your own code — typically the generated *_FullMethodName constants — so a bad value fails at startup. For names that arrive off the wire, use splitFullMethod instead.
func RegisterHookHandler ¶
func RegisterHookHandler[T proto.Message](handler HookHandler[T], opts ...HookOption) error
RegisterHookHandler registers a typed hook handler for the proto message type T. The lookup key is derived from T's proto descriptor full name. At least one of WithOnRequest or WithOnResponse must be provided to specify when the hook is invoked. The generic type parameter T ensures type safety: the handler will only be called with messages of the correct type. This function is typically called during init().
func StreamClientRetry ¶
func StreamClientRetry() grpc.StreamClientInterceptor
StreamClientRetry returns a grpc retry interceptor.
func StreamClientTrailerPropagation ¶
func StreamClientTrailerPropagation() grpc.StreamClientInterceptor
StreamClientTrailerPropagation automatically captures trailers and sets them onto to 'context' tag if they're propagatable.
func StreamServerAIPLogging ¶
func StreamServerAIPLogging() grpc.StreamServerInterceptor
func StreamServerCanonicalize ¶
func StreamServerCanonicalize() grpc.StreamServerInterceptor
func StreamServerDebugInfoScrubber ¶
func StreamServerDebugInfoScrubber() grpc.StreamServerInterceptor
func StreamServerErrorInfoInjector ¶
func StreamServerErrorInfoInjector() grpc.StreamServerInterceptor
func StreamServerFieldMask ¶
func StreamServerFieldMask() grpc.StreamServerInterceptor
func StreamServerHeaderPropagation ¶
func StreamServerHeaderPropagation() grpc.StreamServerInterceptor
func StreamServerHook ¶
func StreamServerHook() grpc.StreamServerInterceptor
StreamServerHook returns a stream server interceptor that invokes hooks on streamed messages. Request hooks are invoked on received messages; response hooks are invoked on sent messages. If no registrations match the stream's method, the stream is passed through unwrapped.
func StreamServerLogContextTagInitializer ¶
func StreamServerLogContextTagInitializer() grpc.StreamServerInterceptor
StreamServerContextTagsInterceptor initializes context tags.
func StreamServerLogging ¶
func StreamServerLogging(logger *slog.Logger) grpc.StreamServerInterceptor
func StreamServerMethodDescriptor ¶
func StreamServerMethodDescriptor() grpc.StreamServerInterceptor
func StreamServerTrailerPropagation ¶
func StreamServerTrailerPropagation() grpc.StreamServerInterceptor
StreamServerTrailer sets a trailers tag onto the context and sends any trailers back to the client.
func StreamServerValidate ¶
func StreamServerValidate(validator protovalidate.Validator) grpc.StreamServerInterceptor
func UnaryClientRetry ¶
func UnaryClientRetry() grpc.UnaryClientInterceptor
UnaryClientRetry returns a gRPC DialOption that adds a default retrying interceptor to all unary RPC calls. Only retries on ResourceExhausted and Unavailable errors.
func UnaryClientTimeout ¶
func UnaryClientTimeout() grpc.UnaryClientInterceptor
func UnaryClientTrailerPropagation ¶
func UnaryClientTrailerPropagation() grpc.UnaryClientInterceptor
UnaryClientTrailerPropagation automatically captures trailers and sets them onto to 'context' tag if they're propagatable. This is only done on 'ctx' that have a trailer tag set. GRPC Servers that use the Trailer Interceptor will have that set.
func UnaryClientValidate ¶
func UnaryClientValidate(validator protovalidate.Validator) grpc.UnaryClientInterceptor
unaryClientValidateInterceptor returns a new unary client interceptor that validates outgoing messages. Invalid messages will be rejected with `InvalidArgument` before sending the request to server.
func UnaryServerAIPLogging ¶
func UnaryServerAIPLogging() grpc.UnaryServerInterceptor
func UnaryServerCanonicalize ¶
func UnaryServerCanonicalize() grpc.UnaryServerInterceptor
func UnaryServerDebugInfoScrubber ¶
func UnaryServerDebugInfoScrubber() grpc.UnaryServerInterceptor
func UnaryServerErrorInfoInjector ¶
func UnaryServerErrorInfoInjector() grpc.UnaryServerInterceptor
func UnaryServerFieldMask ¶
func UnaryServerFieldMask() grpc.UnaryServerInterceptor
func UnaryServerHeaderPropagation ¶
func UnaryServerHeaderPropagation() grpc.UnaryServerInterceptor
func UnaryServerHook ¶
func UnaryServerHook() grpc.UnaryServerInterceptor
UnaryServerHook returns a unary server interceptor that invokes hooks on request and response messages. For requests, hooks registered with WithOnRequest are invoked before the handler. For responses, hooks registered with WithOnResponse are invoked after the handler succeeds. Matchers are evaluated once per RPC; if no registrations match for a direction, the message tree walk is skipped entirely for that direction.
func UnaryServerLogContextTagInitializer ¶
func UnaryServerLogContextTagInitializer() grpc.UnaryServerInterceptor
UnaryServerContextTagsInterceptor initializes context tags.
func UnaryServerLogging ¶
func UnaryServerLogging(logger *slog.Logger) grpc.UnaryServerInterceptor
func UnaryServerMethodDescriptor ¶
func UnaryServerMethodDescriptor() grpc.UnaryServerInterceptor
func UnaryServerTrailerPropagation ¶
func UnaryServerTrailerPropagation() grpc.UnaryServerInterceptor
UnaryServerTrailerPropagation sets a trailers tag onto the context and sends any trailers back to the client.
func UnaryServerValidate ¶
func UnaryServerValidate(validator protovalidate.Validator) grpc.UnaryServerInterceptor
func WithFieldMaskStrict ¶
Types ¶
type HookHandler ¶
HookHandler is a typed function that processes a proto message when a hook is triggered. The handler receives the context and the specific proto message type it was registered for.
type HookMatcher ¶
HookMatcher determines whether a hook should be invoked for a given RPC. It receives the context and the gRPC full method name (e.g. "/package.Service/Method"), which is exactly the value of the generated *_FullMethodName constants. Returning true means the hook will be invoked; false means it will be skipped.
func MatchFullMethods ¶
func MatchFullMethods(fullMethods ...string) HookMatcher
MatchFullMethods returns a HookMatcher that matches if the gRPC full method name is in the given set.
Pass the generated *_FullMethodName constants (e.g. pb.UserService_GetUser_FullMethodName) so a renamed or removed method is a compile error rather than a matcher that silently stops firing.
func MatchMethods ¶
func MatchMethods(methods ...string) HookMatcher
MatchMethods returns a HookMatcher that matches if the RPC method is in the given set.
Methods are bare names, e.g. "GetUser".
func MatchServices ¶
func MatchServices(services ...string) HookMatcher
MatchServices returns a HookMatcher that matches if the RPC service is in the given set.
Services are dotted full names, e.g. "package.Service".
type HookOption ¶
type HookOption func(*hookRegistration)
HookOption configures optional behavior for a hook registration.
func WithHookMatchers ¶
func WithHookMatchers(matchers ...HookMatcher) HookOption
WithHookMatchers sets matcher functions on a hook registration. Can be called multiple times to add additional matchers. All matchers must return true for the hook to be invoked (AND semantics). If no matchers are set, the hook is invoked for all RPCs that contain the registered message type.
func WithHookOnRequest ¶
func WithHookOnRequest() HookOption
WithHookOnRequest configures the hook to be invoked when the registered message type appears anywhere in the request message tree of an RPC.
func WithHookOnResponse ¶
func WithHookOnResponse() HookOption
WithHookOnResponse configures the hook to be invoked when the registered message type appears anywhere in the response message tree of an RPC.
type PropagateOption ¶
type PropagateOption func(*propagateOptions)
func WithHops ¶
func WithHops(n int) PropagateOption