update
This commit is contained in:
1 parent
f25da5f1ee
commit
1df55e75e5
72 files changed
+1401
-1559
No files matched your search
@@ -0,0 +1,46 @@
|
||||
package app
|
||||
|
||||
type Response struct {
|
||||
// 代码
|
||||
Code int `json:"code" example:"200"`
|
||||
// 数据集
|
||||
Data interface{} `json:"data"`
|
||||
// 消息
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
type Page struct {
|
||||
List interface{} `json:"list"`
|
||||
Count int `json:"count"`
|
||||
PageIndex int `json:"pageIndex"`
|
||||
PageSize int `json:"pageSize"`
|
||||
}
|
||||
|
||||
type PageResponse struct {
|
||||
// 代码
|
||||
Code int `json:"code" example:"200"`
|
||||
// 数据集
|
||||
Data Page `json:"data"`
|
||||
// 消息
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
|
||||
func (res *Response) ReturnOK() *Response {
|
||||
res.Code = 200
|
||||
return res
|
||||
}
|
||||
|
||||
func (res *Response) ReturnError(code int) *Response {
|
||||
res.Code = code
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
func (res *PageResponse) ReturnOK() *PageResponse {
|
||||
res.Code = 200
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package msg
|
||||
|
||||
var (
|
||||
CreatedSuccess = "创建成功!"
|
||||
UpdatedSuccess = "更新成功!"
|
||||
DeletedSuccess = "删除成功!"
|
||||
GetSuccess = "查询成功!"
|
||||
NotFound = "未找到相关内容或者数据为空!"
|
||||
)
|
||||
@@ -0,0 +1,44 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 失败数据处理
|
||||
func Error(c *gin.Context, code int, err error, msg string) {
|
||||
var res Response
|
||||
res.Msg = err.Error()
|
||||
if msg != "" {
|
||||
res.Msg = msg
|
||||
}
|
||||
c.JSON(http.StatusOK, res.ReturnError(code))
|
||||
}
|
||||
|
||||
// 通常成功数据处理
|
||||
func OK(c *gin.Context, data interface{}, msg string) {
|
||||
var res Response
|
||||
res.Data = data
|
||||
if msg != "" {
|
||||
res.Msg = msg
|
||||
}
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// 分页数据处理
|
||||
func PageOK(c *gin.Context, result interface{},count int,pageIndex int,pageSize int, msg string) {
|
||||
var res PageResponse
|
||||
res.Data.List = result
|
||||
res.Data.Count = count
|
||||
res.Data.PageIndex = pageIndex
|
||||
res.Data.PageSize = pageSize
|
||||
if msg != "" {
|
||||
res.Msg = msg
|
||||
}
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// 兼容函数
|
||||
func Custum(c *gin.Context, data gin.H) {
|
||||
c.JSON(http.StatusOK,data)
|
||||
}
|
||||
Reference in new issue
Block a user