📋 Context & Problem Description
The gutter/rpc package provides a type-safe RPC client/server bridge. While it is simple to register handlers via rpc.Handle, developers currently lack a clean mechanism to inject cross-cutting server concerns (e.g. logging, JWT validation, rate limiting, CORS configuration, error metrics) globally or per-procedure. Implementing these manually inside every handler leads to bloated boilerplate.
💡 Proposed Solution & Implementation Plan
Add middleware chain support to Gutter RPC:
- Define Middleware Signature:
type Middleware func(next http.Handler) http.Handler
Or a custom context-aware RPC handler chain wrapper:
type RPCMiddleware func(route string, next invoker) invoker
- Global & Group Middleware Registrations:
Introduce registration helpers on the server side:
rpc.Use(mw ...Middleware) to apply middlewares to the main /rpc multiplexer.
- Add support for routing groups or prefix-based middleware filtering.
- Context Injection:
Ensure values extracted by middleware (such as an authenticated UserClaim struct) are passed cleanly down the context.Context to the final RPC handler.
🎯 Impact & Benefits
- Clean Code Architecture: Keeps RPC handlers focused solely on business logic.
- Production Security: Straightforward integration of rate-limiters, CORS, and auth checks.
🏷️ Suggested Labels
feature, rpc, security
📋 Context & Problem Description
The
gutter/rpcpackage provides a type-safe RPC client/server bridge. While it is simple to register handlers viarpc.Handle, developers currently lack a clean mechanism to inject cross-cutting server concerns (e.g. logging, JWT validation, rate limiting, CORS configuration, error metrics) globally or per-procedure. Implementing these manually inside every handler leads to bloated boilerplate.💡 Proposed Solution & Implementation Plan
Add middleware chain support to Gutter RPC:
Introduce registration helpers on the server side:
rpc.Use(mw ...Middleware)to apply middlewares to the main/rpcmultiplexer.Ensure values extracted by middleware (such as an authenticated
UserClaimstruct) are passed cleanly down thecontext.Contextto the final RPC handler.🎯 Impact & Benefits
🏷️ Suggested Labels
feature,rpc,security