mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-14 01:37: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:
@@ -47,9 +47,9 @@ type apiKeyStatsFlushEntry struct {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body statsFlushRequest true "Stats to flush"
|
||||
// @Success 200 {object} gin.H
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /internal/stats/flush [post]
|
||||
func (h *InternalHandler) FlushStats(c *gin.Context) {
|
||||
if h == nil || h.db == nil {
|
||||
@@ -124,9 +124,9 @@ func (h *InternalHandler) FlushStats(c *gin.Context) {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body apiKeyStatsFlushRequest true "Stats to flush"
|
||||
// @Success 200 {object} gin.H
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /internal/apikey-stats/flush [post]
|
||||
func (h *InternalHandler) FlushAPIKeyStats(c *gin.Context) {
|
||||
if h == nil || h.db == nil {
|
||||
@@ -287,9 +287,9 @@ const alertDeduplicationCooldown = 5 * time.Minute
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body reportAlertsRequest true "Alerts to report"
|
||||
// @Success 200 {object} reportAlertsResponse
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=reportAlertsResponse}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /internal/alerts/report [post]
|
||||
func (h *InternalHandler) ReportAlerts(c *gin.Context) {
|
||||
if h == nil || h.db == nil {
|
||||
|
||||
Reference in New Issue
Block a user