1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package controller
- import (
- "github.com/gin-gonic/gin"
- "icloudapp.cn/tools/entity"
- "net/http"
- )
- type ResponseData struct {
- Code entity.ResCode `json:"code"`
- Msg interface{} `json:"msg"`
- Body interface{} `json:"data,omitempty"`
- }
- type ResponseBodyData struct {
- Code entity.ResCode `json:"code"`
- Msg interface{} `json:"msg"`
- Body interface{} `json:"body:omitempty"`
- }
- func ResponseError(c *gin.Context, code entity.ResCode) {
- c.JSON(http.StatusOK, &ResponseData{
- Code: code,
- Msg: code.Msg(),
- Body: nil,
- })
- }
- func ResponseErrorWithMsg(c *gin.Context, code entity.ResCode, msg interface{}) {
- c.JSON(http.StatusOK, &ResponseData{
- Code: code,
- Msg: msg,
- Body: nil,
- })
- }
- func ResponseSuccess(c *gin.Context, data interface{}) {
- c.JSON(http.StatusOK, &ResponseData{
- Code: entity.CodeSuccess,
- Msg: entity.CodeSuccess.Msg(),
- Body: data,
- })
- }
- func ResponseNormal(c *gin.Context, code entity.ResCode, msg interface{}, body interface{}) {
- c.JSON(http.StatusOK, &ResponseData{
- Code: code,
- Msg: msg,
- Body: body,
- })
- }
- func ResponseBody(c *gin.Context, code entity.ResCode, msg interface{}, body interface{}) {
- c.JSON(http.StatusOK, &ResponseBodyData{
- Code: code,
- Msg: msg,
- Body: body,
- })
- }
|