Documentation
¶
Overview ¶
Package interceptor holds hand-written gRPC interceptors: request id, logging and panic recovery. No third-party middleware packages are required.
Index ¶
- Constants
- func RequestIDFrom(ctx context.Context) string
- func StreamAuth(token string) grpc.StreamServerInterceptor
- func StreamLogging(logger *slog.Logger) grpc.StreamServerInterceptor
- func StreamRecover(logger *slog.Logger) grpc.StreamServerInterceptor
- func StreamRequestID() grpc.StreamServerInterceptor
- func UnaryAuth(token string) grpc.UnaryServerInterceptor
- func UnaryLogging(logger *slog.Logger) grpc.UnaryServerInterceptor
- func UnaryRecover(logger *slog.Logger) grpc.UnaryServerInterceptor
- func UnaryRequestID() grpc.UnaryServerInterceptor
- type Bearer
Constants ¶
const AuthHeader = "authorization"
AuthHeader is the metadata key carrying "Bearer <GRPC_TOKEN>".
const MaxRequestIDLen = 128
MaxRequestIDLen bounds a client-supplied request id. Anything longer, or not printable ASCII, is replaced with a generated id: the value is logged and echoed back, so it must not be a vehicle for log injection or bloat.
const RequestIDHeader = "x-request-id"
RequestIDHeader is the metadata key used to propagate request identifiers.
Variables ¶
This section is empty.
Functions ¶
func RequestIDFrom ¶
RequestIDFrom returns the request id stored in ctx, or "".
func StreamAuth ¶
func StreamAuth(token string) grpc.StreamServerInterceptor
StreamAuth is UnaryAuth for streaming RPCs (WorkerService, reflection).
func StreamLogging ¶
func StreamLogging(logger *slog.Logger) grpc.StreamServerInterceptor
StreamLogging emits one structured log line per stream RPC (when the stream ends).
func StreamRecover ¶
func StreamRecover(logger *slog.Logger) grpc.StreamServerInterceptor
StreamRecover converts stream handler panics into codes.Internal and logs the stack.
func StreamRequestID ¶
func StreamRequestID() grpc.StreamServerInterceptor
StreamRequestID is the stream variant of the request id interceptor.
func UnaryAuth ¶
func UnaryAuth(token string) grpc.UnaryServerInterceptor
UnaryAuth rejects every call except the health service unless it carries "authorization: Bearer <token>". An empty token disables the check (the config layer decides when that is allowed).
func UnaryLogging ¶
func UnaryLogging(logger *slog.Logger) grpc.UnaryServerInterceptor
UnaryLogging emits one structured log line per unary RPC.
func UnaryRecover ¶
func UnaryRecover(logger *slog.Logger) grpc.UnaryServerInterceptor
UnaryRecover converts handler panics into codes.Internal and logs the stack.
func UnaryRequestID ¶
func UnaryRequestID() grpc.UnaryServerInterceptor
UnaryRequestID is the unary variant of the request id interceptor.
Types ¶
type Bearer ¶
type Bearer string
Bearer is the client side: per-RPC credentials that send "authorization: Bearer <token>". jobrund speaks plaintext gRPC, so the token crosses the wire in clear; put TLS (or a private network) in front when it leaves the host.
func (Bearer) GetRequestMetadata ¶
GetRequestMetadata implements credentials.PerRPCCredentials.
func (Bearer) RequireTransportSecurity ¶
RequireTransportSecurity implements credentials.PerRPCCredentials: false, because the transport is insecure by design (see the type comment).