feat(api): align response envelope schema

Switch response envelope business code to numeric and make message
consistently present. Add trace_id and optional details, and remove the
duplicate DTO envelope definition. Improve middleware path exclusion
handling and add a time-based trace ID fallback if crypto RNG fails.

BREAKING CHANGE: response envelope `code` is now `int` (was `string`) and
`message` semantics/defaults changed; clients must update parsing.
This commit is contained in:
zenfun
2026-01-10 01:09:05 +08:00
parent 26733be020
commit ac6a1858cf
3 changed files with 20 additions and 66 deletions

View File

@@ -1,12 +1,16 @@
package api
// ResponseEnvelope is the standard wrapper for EZ-API JSON responses.
// Code is a stable business code string (e.g., ok, invalid_request, not_found).
// Message is empty for success and mirrors the top-level error for failures.
// Data holds the original response payload.
// Code is a numeric business code: 0 for success, non-zero for errors.
// Message is "success" for success, error description for failures.
// Data holds the original response payload for success; null for errors.
// TraceID is a request correlation identifier.
// Details holds optional structured error information.
// swagger:model ResponseEnvelope
type ResponseEnvelope struct {
Code string `json:"code" example:"ok"`
Code int `json:"code" example:"0"`
Message string `json:"message" example:"success"`
Data any `json:"data" swaggertype:"object"`
Message string `json:"message" example:""`
TraceID string `json:"trace_id" example:"a1b2c3d4e5f6g7h8"`
Details any `json:"details,omitempty" swaggertype:"object"`
}