(ctx context.Context)
| 128 | } |
| 129 | |
| 130 | func (rl *PerClientRateLimiter) extractClientID(ctx context.Context) string { |
| 131 | // Prefer user identity from JWT/auth context |
| 132 | if user := UserFromContext(ctx); user != nil { |
| 133 | return user.Subject |
| 134 | } |
| 135 | // Fall back to peer address |
| 136 | if p, ok := peer.FromContext(ctx); ok { |
| 137 | return p.Addr.String() |
| 138 | } |
| 139 | return "unknown" |
| 140 | } |
| 141 | |
| 142 | func (rl *PerClientRateLimiter) getLimiter(clientID string) *rate.Limiter { |
| 143 | rl.mu.Lock() |
no test coverage detected