diff --git a/resp/response.go b/resp/response.go index 21a0474f1f2e4755a8a57d1a64b6a4ebc3ed9ff2..7a40d78b35fb5c71f35d06a461c4f5bfbb9bc769 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) +}