From cd9c8da7356296dda6d4a873937832529a994c00 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Mon, 13 Mar 2023 14:39:55 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=88=86=E9=A1=B5=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resp/response.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/resp/response.go b/resp/response.go index 21a0474..7a40d78 100644 --- a/resp/response.go +++ b/resp/response.go @@ -135,3 +135,29 @@ func ResponsePageOk(c *gin.Context, data interface{}, total uint, index int) { traceId, _ := c.Get(mycontext.TRACEID) mylogrus.MyLog.Infof("ResponsePageOk traceId: %s, JSON takes %v", traceId, timeDiff) } + +type PageRespBase struct { + NextPageIndex int `json:"nextPageIndex"` + HasNextPage bool `json:"hasNextPage"` + Data interface{} `json:"data"` // 需要具体自定义 +} + +// 分页返回 +// 客户端入参 PageReqBase +// 服务端返回 PageRespBase +func ResponsePageBaseOk(c *gin.Context, data interface{}, nextPageIndex int, hasNextPage bool) { + if data == nil { + data = make([]interface{}, 0) + } + response := Response{ + Code: myerr.GetSuccessCode(), + Message: myerr.GetSuccessMsg(), + OperationMessage: myerr.GetSuccessMsg(), + Data: PageRespBase{ + NextPageIndex: nextPageIndex, + HasNextPage: hasNextPage, + Data: data, + }, + } + c.JSON(http.StatusOK, response) +} -- 2.22.0