Help us shape the future of Go! Take the 2026 Go Developer Survey

interceptor

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package interceptor holds hand-written gRPC interceptors: request id, logging and panic recovery. No third-party middleware packages are required.

Index

Constants

View Source
const AuthHeader = "authorization"

AuthHeader is the metadata key carrying "Bearer <GRPC_TOKEN>".

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

View Source
const RequestIDHeader = "x-request-id"

RequestIDHeader is the metadata key used to propagate request identifiers.

Variables

This section is empty.

Functions

func RequestIDFrom

func RequestIDFrom(ctx context.Context) string

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

func (b Bearer) GetRequestMetadata(context.Context, ...string) (map[string]string, error)

GetRequestMetadata implements credentials.PerRPCCredentials.

func (Bearer) RequireTransportSecurity

func (Bearer) RequireTransportSecurity() bool

RequireTransportSecurity implements credentials.PerRPCCredentials: false, because the transport is insecure by design (see the type comment).

Jump to

Keyboard shortcuts

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