Documentation
¶
Overview ¶
Package grpckit provides gRPC server utilities including standard interceptors for logging, panic recovery, and health-check registration.
Index ¶
- func RegisterHealth(server *grpc.Server, checker HealthChecker)
- func StreamLogging(logger *slog.Logger) grpc.StreamServerInterceptor
- func StreamMetrics(logger *slog.Logger) grpc.StreamServerInterceptor
- func StreamRecovery(logger *slog.Logger) grpc.StreamServerInterceptor
- func UnaryLogging(logger *slog.Logger) grpc.UnaryServerInterceptor
- func UnaryMetrics(logger *slog.Logger) grpc.UnaryServerInterceptor
- func UnaryRecovery(logger *slog.Logger) grpc.UnaryServerInterceptor
- type HealthChecker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterHealth ¶
func RegisterHealth(server *grpc.Server, checker HealthChecker)
RegisterHealth registers a grpc.health.v1.Health service on the given gRPC server. The Check RPC calls the provided checker and maps the result to a gRPC health status: SERVING when the checker returns nil, NOT_SERVING when it returns an error.
func StreamLogging ¶
func StreamLogging(logger *slog.Logger) grpc.StreamServerInterceptor
StreamLogging returns a stream server interceptor that logs the method name and duration for each stream RPC at Info level.
func StreamMetrics ¶
func StreamMetrics(logger *slog.Logger) grpc.StreamServerInterceptor
StreamMetrics returns a stream server interceptor that records RPC metrics. This is a placeholder that logs method and duration; replace the body with your preferred metrics library (e.g., Prometheus, OpenTelemetry).
func StreamRecovery ¶
func StreamRecovery(logger *slog.Logger) grpc.StreamServerInterceptor
StreamRecovery returns a stream server interceptor that catches panics in the handler, logs them at Error level, and returns a codes.Internal gRPC status.
func UnaryLogging ¶
func UnaryLogging(logger *slog.Logger) grpc.UnaryServerInterceptor
UnaryLogging returns a unary server interceptor that logs the method name, duration, and error (if any) for each RPC at Info level.
func UnaryMetrics ¶
func UnaryMetrics(logger *slog.Logger) grpc.UnaryServerInterceptor
UnaryMetrics returns a unary server interceptor that records RPC metrics. This is a placeholder that logs method and duration; replace the body with your preferred metrics library (e.g., Prometheus, OpenTelemetry).
func UnaryRecovery ¶
func UnaryRecovery(logger *slog.Logger) grpc.UnaryServerInterceptor
UnaryRecovery returns a unary server interceptor that catches panics in the handler, logs them at Error level, and returns a codes.Internal gRPC status.
Types ¶
type HealthChecker ¶
HealthChecker is a function that performs health checks and returns an error when any check fails. This decouples grpckit from the health package — callers typically pass the result of health.All(checks).