package api import ( "net/http" "github.com/gin-gonic/gin" ) // ApiResponse 与 Java 一致:{ code, message, data };成功 code=0。 // // 探活 /health、/ready 不走这个外壳,编排系统要直接读 ok 字段。 type ApiResponse struct { Code int `json:"code"` Message string `json:"message"` Data interface{} `json:"data"` } func OK(c *gin.Context, data interface{}) { c.JSON(http.StatusOK, ApiResponse{Code: 0, Message: "ok", Data: data}) } func Created(c *gin.Context, data interface{}) { c.JSON(http.StatusCreated, ApiResponse{Code: 0, Message: "ok", Data: data}) } func Fail(c *gin.Context, httpStatus, code int, msg string) { c.JSON(httpStatus, ApiResponse{Code: code, Message: msg, Data: nil}) }