1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- package entity
- import (
- "github.com/gin-gonic/gin"
- "net/http"
- )
- type ResponseData struct {
- Code ResCode `json:"code"`
- Msg interface{} `json:"msg"`
- Body interface{} `json:"data,omitempty"`
- }
- type ResponseBodyData struct {
- Code ResCode `json:"code"`
- Msg interface{} `json:"msg"`
- Body interface{} `json:"body,omitempty"`
- }
- type ResponseNormalBody struct {
- Code int `json:"code"`
- Msg interface{} `json:"msg"`
- Body interface{} `json:"body,omitempty"`
- }
- type ResponseNormalData struct {
- Code int `json:"code"`
- Msg interface{} `json:"msg"`
- Body interface{} `json:"data,omitempty"`
- }
- func ResponseError(c *gin.Context, code ResCode) {
- c.JSON(http.StatusOK, &ResponseData{
- Code: code,
- Msg: code.Msg(),
- Body: nil,
- })
- }
- func ResponseErrorWithMsg(c *gin.Context, code 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: CodeSuccess,
- Msg: CodeSuccess.Msg(),
- Body: data,
- })
- }
- func ResponseNormal(c *gin.Context, code ResCode, msg interface{}, body interface{}) {
- c.JSON(http.StatusOK, &ResponseData{
- Code: code,
- Msg: msg,
- Body: body,
- })
- }
- func ResponseBody(c *gin.Context, code ResCode, msg interface{}, body interface{}) {
- c.JSON(http.StatusOK, &ResponseBodyData{
- Code: code,
- Msg: msg,
- Body: body,
- })
- }
- func ResponseHandleBody(c *gin.Context, code int, msg interface{}, body interface{}) {
- c.JSON(http.StatusOK, &ResponseNormalBody{
- Code: code,
- Msg: msg,
- Body: body,
- })
- }
- func EmptyBodyObject() map[string]interface{} {
- return map[string]interface{}{}
- }
- func EmptyBodyArray() []interface{} {
- return []interface{}{}
- }
|