package common import ( "github.com/gin-gonic/gin" "net/http" ) type ResponseJson struct { Code uint `yaml:"code" json:"code"` // response code Message string `yaml:"message" json:"message"` // response message Data interface{} `yaml:"data" json:"data,omitempty"` // response data } /** 返回成功Response */ func ReturnSuccess(c *gin.Context, data interface{}) { if data != nil { c.JSON(http.StatusOK, gin.H{ "code": 200, "message": "SUCCESS", "data": data, }) } else { c.JSON(http.StatusOK, gin.H{ "code": 200, "message": "SUCCESS", }) } } /** 返回失败Response */ func ReturnFailure(c *gin.Context, code int) { c.JSON(http.StatusOK, gin.H{ "code": code, "message": ErrorMap[code], }) } func ReturnFailureMsg(c *gin.Context, code int, msg string) { c.JSON(http.StatusOK, gin.H{ "code": code, "message": msg, }) }