Some checks failed
CI / Build & Test (push) Failing after 33s
- 37 个端点全部添加 godoc Swagger 注解(RBAC 11 / Org 5 / Audit 1 / Settings 7 / Notification 7) - 重新生成 docs/(swagger.json/yaml/docs.go) - M8 质量横切:IP 限流、安全头、Body 限制、结构化日志增强、优雅关闭 - 新增 Dockerfile 多阶段构建 + .dockerignore - 新增 testutil 测试工具包 - 修复 testutil.go 编译错误
24 lines
552 B
Go
24 lines
552 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"mengstack/internal/kernel/errors"
|
|
"mengstack/internal/kernel/response"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// BodyLimit restricts the maximum request body size.
|
|
func BodyLimit(maxBytes int64) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
if c.Request.ContentLength > maxBytes {
|
|
response.Fail(c, errors.New("BODY_TOO_LARGE", "request body too large", http.StatusRequestEntityTooLarge))
|
|
c.Abort()
|
|
return
|
|
}
|
|
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, maxBytes)
|
|
c.Next()
|
|
}
|
|
}
|