Skip to content

[Feature] Middleware Chain Support in Gutter RPC #12

@HaHiepThanh

Description

@HaHiepThanh

📋 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:

  1. 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
  2. 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.
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions