diff --git a/core/response.go b/core/response.go index 086016e..f4cc8e1 100644 --- a/core/response.go +++ b/core/response.go @@ -3,6 +3,7 @@ package core import ( "github.com/gin-gonic/gin" "net/http" + "online_code/utils" ) // 返回数据包装 @@ -59,6 +60,15 @@ func (r rs) OkDetailed(data interface{}, message string) { r.Result(SUCCESS, data, message) } +// OkDataPage 返回分页数据 +func (r rs) OkDataPage(count int64, page PageData) { + // 计算总页码 + totalPage := utils.GenTotalPage(count, page.Size) + page.TotalPage = totalPage + // 返回结果 + r.Result(SUCCESS, page, "操作成功") +} + // Fail 返回默认失败 func (r rs) Fail() { r.Result(ERROR, nil, "操作失败") diff --git a/go.mod b/go.mod index 206d81b..21ff359 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/fsnotify/fsnotify v1.5.1 github.com/gin-gonic/gin v1.7.7 github.com/go-redis/redis/v8 v8.11.5 - github.com/google/uuid v1.1.2 github.com/spf13/viper v1.10.1 golang.org/x/crypto v0.0.0-20220214200702-86341886e292 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c diff --git a/route/router.go b/route/router.go index 9cbf193..d98aa36 100644 --- a/route/router.go +++ b/route/router.go @@ -4,4 +4,5 @@ import "github.com/gin-gonic/gin" func InitRoute(g *gin.RouterGroup) { problem(g.Group("/problem")) + user(g.Group("/user")) }