mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-14 03:17:52 +00:00
feat(api): wrap JSON responses in envelope
Add response envelope middleware to standardize JSON responses as
`{code,data,message}` with consistent business codes across endpoints.
Update Swagger annotations and tests to reflect the new response shape.
BREAKING CHANGE: API responses are now wrapped in a response envelope; clients must read payloads from `data` and handle `code`/`message` fields.
This commit is contained in:
@@ -41,10 +41,10 @@ type MasterUsageStatsResponse struct {
|
||||
// @Param period query string false "today|week|month|all"
|
||||
// @Param since query int false "unix seconds"
|
||||
// @Param until query int false "unix seconds"
|
||||
// @Success 200 {object} MasterUsageStatsResponse
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 401 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=MasterUsageStatsResponse}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 401 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /v1/stats [get]
|
||||
func (h *MasterHandler) GetSelfStats(c *gin.Context) {
|
||||
master, exists := c.Get("master")
|
||||
@@ -147,9 +147,9 @@ type AdminUsageStatsResponse struct {
|
||||
// @Param period query string false "today|week|month|all"
|
||||
// @Param since query int false "unix seconds"
|
||||
// @Param until query int false "unix seconds"
|
||||
// @Success 200 {object} AdminUsageStatsResponse
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=AdminUsageStatsResponse}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/stats [get]
|
||||
func (h *AdminHandler) GetAdminStats(c *gin.Context) {
|
||||
rng, err := parseStatsRange(c)
|
||||
|
||||
Reference in New Issue
Block a user