Repository navigation
Conversation
…、脱敏基线 - request id:gin context 键统一为 response.RequestIDKey(request_id),移除 「中间件把 id 写回入站头」的隐性依赖;入站 X-Request-ID 限 128 字符 + [A-Za-z0-9_-] 白名单,非法即服务端重新生成;中间件从 cmd 移入 internal/middleware - access 日志:每请求一行 INFO access(request_id/method/route=FullPath/ http_status/biz_code/user_id/duration_ms/client_ip/host/version); 业务码非成功时额外一行 ERROR request failed,同 request_id 可配对; user_id 取自已鉴权 principal,匿名记 anonymous,绝不记明文 token - 结构化日志:slog 统一 JSONHandler 到 stdout,新增 LOG_LEVEL (debug/info/warn/error,非法值回落 info 并 warn 一次) - 脱敏基线:新增 internal/logx.Redact(连接串 userinfo、password=、token=、 Bearer、di_pat_、sk-),response.Error 的错误文本经同一 helper 收口 - 文档:production.md 补 LOG_LEVEL、jq 过滤示例与多副本按 request_id 聚合口径; .env.example 补 LOG_LEVEL Closes #221
This was referenced Oct 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
做了什么
R-96(issue #221)四条断线全修:
response.RequestIDKey(request_id),response.getTraceID改为 context 优先、入站头回落;移除「中间件把 id 写回入站头」的隐性依赖。中间件从cmd移入internal/middleware(含测试)。internal/middleware.AccessLog每请求一行INFO access(request_id / method / route=FullPath / http_status / biz_code / user_id / duration_ms / client_ip / host / version);业务码非成功时额外一行ERROR request failed,同 request_id 配对。user_id 取自 principal,匿名记 anonymous,绝不记明文 token(有测试钉死)。LOG_LEVEL(非法值回落 info 并 warn 一次);production.md补 jq 示例与多副本按 request_id 聚合口径。internal/logx.Redact(连接串 userinfo / password= / token= / Bearer / di_pat_ / sk-,17 个表驱动用例);response.Error的响应文本经同一 helper 收口。X-Request-ID限 128 字符 +[A-Za-z0-9_-],非法即重新生成(不透传不报错)。怎么验证
go vet ./...+go test -race ./...全绿(新增 logx / middleware / response 用例:trace 双分支钉住、失败配对两行、并发 100 失败请求 id 唯一且每 id 恰好两行、脱敏 17 例、LOG_LEVEL 解析)。trace== 响应头X-Request-ID(不再依赖 header 回写副作用)✅X-Request-ID: probe-123→trace==probe-123✅;换行注入/超长 id → 服务端重新生成 ✅route为 FullPath 模板、user_id=anonymous、含 host/version ✅Closes #221