🎨 新增路由||优化返回数据结构

This commit is contained in:
loser 2022-06-02 16:22:36 +08:00
parent fb5f8ca2a5
commit 569e6618a8
3 changed files with 11 additions and 1 deletions

View File

@ -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, "操作失败")

1
go.mod
View File

@ -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

View File

@ -4,4 +4,5 @@ import "github.com/gin-gonic/gin"
func InitRoute(g *gin.RouterGroup) {
problem(g.Group("/problem"))
user(g.Group("/user"))
}