增加安全字段校验提示、请求预算和就绪/存活探针, 让绑定、数据库、Redis 和出站响应解码保留可信诊断上下文。 补充完整应用装配及逆序清理示例,同步接入和迁移文档。 验证:make verify、make race-check 全部通过。 BREAKING CHANGE: 普通 Controller 默认启用 30 秒协作式请求预算, 可用 request_timeout_ms: 0 或 max-exec-time:"0" 关闭; 字段校验失败的 400 响应增加安全字段明细。
This commit is contained in:
1 parent
b4c3ac622c
commit
3196e45a01
22 files changed
+1294
-79
No files matched your search
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"git.zhangdeman.cn/github/ginframework/diagnostic"
|
||||
"git.zhangdeman.cn/github/ginframework/fault"
|
||||
"git.zhangdeman.cn/github/ginframework/http/request"
|
||||
failure "git.zhangdeman.cn/github/ginframework/internal/failure"
|
||||
"git.zhangdeman.cn/github/ginframework/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -41,6 +42,11 @@ const (
|
||||
codeTrustedType = 900424
|
||||
codeRouteFrozen = 900425
|
||||
codeRoutePath = 900426
|
||||
codeRequestBudget = 900427
|
||||
codeRequestTimeout = 900428
|
||||
codeHealthConfig = 900429
|
||||
codeReadinessCheck = 900430
|
||||
codeRequestCancelled = 900431
|
||||
)
|
||||
|
||||
// PublicError 是业务显式允许公开的错误,不包含原始原因文本。
|
||||
@@ -100,6 +106,13 @@ func (s *Server) writeResult(ctx *gin.Context, data any, err error, status int)
|
||||
}
|
||||
if status != 0 {
|
||||
public = &PublicError{Code: status, Message: http.StatusText(status), Status: status}
|
||||
var (
|
||||
validation *request.ValidationError
|
||||
)
|
||||
if status == http.StatusBadRequest && errors.As(err, &validation) {
|
||||
public.Message = "Validation failed"
|
||||
public.Data = request.ValidationDetails{Fields: validation.Fields}
|
||||
}
|
||||
}
|
||||
result.Code, result.Message, result.Data = public.Code, public.Message, public.Data
|
||||
status = public.Status
|
||||
|
||||