Files
Agent-System-Backend/internal/server/ratelimit.go
T
weichen f1302ed5b3 Enable canonical versioned Go module consumption
Why: Allow consumers to download an immutable module revision without nested source checkouts or local path replacements.

Evidence: SELF package tests and the prior canonical-path rejection are recorded in the Dev dependency-workspace task card; remote consumption is replayed against the committed candidate.

Impact: Change the module identity and its Go imports while preserving API behavior. Existing historical submodule revisions remain buildable.

Refs: Versioned dependencies U1/U3; feature/dependency-workspace
2026-10-13 15:47:16 +00:00

27 lines
859 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package server
import (
"net/http"
"time"
"git-ssh.u1680832.nyat.app/weichen/Agent-System-Backend.git/internal/ratelimit"
)
// 限流中间件(阶段 3):按租户 owner 固定窗口;limit<=0(默认)直接放行。
// 位于认证之后(key=owner);Limiter/LimitLookup 由组合根注入。
func (s *Server) withRateLimit(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if s.Limiter != nil && s.LimitLookup != nil {
if limit := s.LimitLookup(); limit > 0 {
if !s.Limiter.Allow(r.Context(), "owner:"+s.owner(r), limit, time.Minute) {
http.Error(w, "rate limit exceeded(runtime.rateLimitPerMin)", http.StatusTooManyRequests)
return
}
}
}
next.ServeHTTP(w, r)
})
}
var _ = ratelimit.Memory{} // 接口形状锚点(Limiter 注入自组合根)