MCPcopy Create free account
hub / github.com/InferCore/InferCore / allowByRateLimit

Method allowByRateLimit

internal/policy/basic_engine.go:84–105  ·  view source on GitHub ↗
(tenantID string, limit int)

Source from the content-addressed store, hash-verified

82}
83
84func (e *BasicEngine) allowByRateLimit(tenantID string, limit int) bool {
85 if limit <= 0 {
86 return true
87 }
88
89 nowSec := time.Now().Unix()
90 e.mu.Lock()
91 defer e.mu.Unlock()
92
93 if e.windowSecond != nowSec {
94 e.windowSecond = nowSec
95 e.tenantCounts = map[string]int{}
96 }
97
98 current := e.tenantCounts[tenantID]
99 if current >= limit {
100 return false
101 }
102
103 e.tenantCounts[tenantID] = current + 1
104 return true
105}
106
107func validateAgentTenantLimits(req types.AIRequest, tenant config.TenantConfig) error {
108 if !strings.EqualFold(strings.TrimSpace(req.RequestType), types.RequestTypeAgent) {

Callers 1

EvaluateMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected