grpckit

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package grpckit provides gRPC server utilities including standard interceptors for logging, panic recovery, and health-check registration.

Index

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

type HealthChecker func(ctx context.Context) error

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).

Jump to

Keyboard shortcuts

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