Files
jiu/backend/internal/util/response.go
T
wangjia 3ab78dbf7a fix(backend): 架构质量改进批次二 (#32-37)
- #32 License 激活迁移到 license_devices 表:Activate/Verify/Deactivate 全部改用
  license_devices,新增 max_devices 校验和 GET /license/devices 端点;
  Activate 现在校验 shop_id 防跨租户激活
- #33 checkInventory 从 StockOutHandler 移到 StockService.CheckInventoryAvailability
- #34 新增 util/response.go 统一错误响应工具(RespondError/RespondSuccess/RespondCreated)
- #35 生产模式 CORS Origin='*' 启动时 Fatal
- #36 生产模式 License 私钥未配置启动时 Fatal
- #37 新增 util/page.go ValidatePageSize,应用到 partner/product/stock_in/stock_out handler

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-11 00:38:49 +08:00

23 lines
593 B
Go

package util
import (
"net/http"
"github.com/gin-gonic/gin"
)
// RespondError writes a structured error response: {"code": code, "message": msg}.
func RespondError(c *gin.Context, status int, code, msg string) {
c.JSON(status, gin.H{"code": code, "message": msg})
}
// RespondSuccess writes {"data": data} with HTTP 200.
func RespondSuccess(c *gin.Context, data interface{}) {
c.JSON(http.StatusOK, gin.H{"data": data})
}
// RespondCreated writes {"data": data} with HTTP 201.
func RespondCreated(c *gin.Context, data interface{}) {
c.JSON(http.StatusCreated, gin.H{"data": data})
}