go-grpc-middleware
Golang gRPC Middlewares: interceptor chaining, auth, logging, retries and more.
This Go library provides a collection of middleware pieces for gRPC, which is a popular way for services in a backend system to talk to each other. The idea is that when one service calls another over gRPC, you often want certain things to happen automatically on every call: logging what happened, checking whether the caller is authorized, counting how many requests came in, and so on. This library gives developers ready-made building blocks for exactly that.
In gRPC, these building blocks are called interceptors. An interceptor sits between the network request and the actual code that handles it, so it can inspect, log, or reject the request before the main logic ever runs. This library provides interceptors for authentication, structured logging, request retries on failure, rate limiting, input validation from schema definitions, panic recovery (turning crashes into proper error responses), and request timeouts. Most of these work on both the server side and the client side of a connection.
One of the library's main features is chaining: you can stack multiple interceptors in a specific order, so a request passes through authentication, then logging, then validation, all before reaching your own code. The repository includes working example code showing how to wire these together with observability tools for tracking request metrics and traces.
The logging interceptor is designed to work with several popular Go logging libraries rather than locking you into one. Prometheus-based metrics are provided through an included provider package that was migrated from an older, now-deprecated sibling project.
The library targets Go developers building microservices with gRPC who want to avoid writing the same cross-cutting concerns by hand for every service. The README notes that simpler interceptors can also be copied directly into your own project if you need more control over edge cases.