增加安全字段校验提示、请求预算和就绪/存活探针, 让绑定、数据库、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
@@ -0,0 +1,33 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
failure "git.zhangdeman.cn/github/ginframework/internal/failure"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// finishCanceled 在合作式预算结束后统一返回超时响应,保留已分类错误的日志语义。
|
||||
// 入参:ctx 为当前请求,cause 为已接收的下层错误,允许 nil。
|
||||
// 返回:上下文结束并应停止当前流程时为 true;客户端取消时不继续写响应。
|
||||
func (s *Server) finishCanceled(ctx *gin.Context, cause error) bool {
|
||||
err := ctx.Request.Context().Err()
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
if cause == nil {
|
||||
cause = err
|
||||
}
|
||||
code, summary := codeRequestCancelled, "HTTP request cancelled"
|
||||
if errors.Is(err, context.DeadlineExceeded) {
|
||||
code, summary = codeRequestTimeout, "HTTP request budget exceeded"
|
||||
}
|
||||
classified := failure.WrapContext(ctx.Request.Context(), code, summary, cause)
|
||||
if errors.Is(err, context.DeadlineExceeded) {
|
||||
s.writeResult(ctx, nil, classified, http.StatusGatewayTimeout)
|
||||
}
|
||||
ctx.Abort()
|
||||
return true
|
||||
}
|
||||