MCPcopy Create free account
hub / github.com/PatchMon/PatchMon / checkRateLimit

Method checkRateLimit

server-source-code/internal/handler/ai.go:40–54  ·  view source on GitHub ↗

checkRateLimit returns true if the request is allowed (under limit).

(ctx context.Context, userID string)

Source from the content-addressed store, hash-verified

38
39// checkRateLimit returns true if the request is allowed (under limit).
40func (h *AIHandler) checkRateLimit(ctx context.Context, userID string) bool {
41 rdb := h.rdb.RDB(ctx)
42 if rdb == nil || userID == "" {
43 return true
44 }
45 key := "ratelimit:ai:" + userID
46 count, err := rdb.Incr(ctx, key).Result()
47 if err != nil {
48 return true // fail open
49 }
50 if count == 1 {
51 _ = rdb.Expire(ctx, key, rateLimitWindow).Err()
52 }
53 return count <= rateLimitMax
54}
55
56// GetProviders returns available AI providers and models.
57func (h *AIHandler) GetProviders(w http.ResponseWriter, r *http.Request) {

Callers 2

AssistMethod · 0.95
CompleteMethod · 0.95

Calls 1

RDBMethod · 0.80

Tested by

no test coverage detected