You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1007 B
47 lines
1007 B
1 month ago
|
// 在 shared/model/response.go 中添加以下内容
|
||
|
package model
|
||
|
|
||
|
import "github.com/gin-gonic/gin"
|
||
|
|
||
|
// 基础响应结构
|
||
|
type BaseResponse struct {
|
||
|
Success bool `json:"success"`
|
||
|
Message string `json:"message,omitempty"`
|
||
|
Data interface{} `json:"data,omitempty"`
|
||
|
}
|
||
|
|
||
|
// 分页响应结构
|
||
|
type PaginationResponse struct {
|
||
|
BaseResponse
|
||
|
Total int64 `json:"total"`
|
||
|
Page int `json:"page"`
|
||
|
PageSize int `json:"pageSize"`
|
||
|
}
|
||
|
|
||
|
// NewSuccessResponse 创建成功响应
|
||
|
func NewSuccessResponse(data interface{}) gin.H {
|
||
|
return gin.H{
|
||
|
"success": true,
|
||
|
"data": data,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// NewErrorResponse 创建错误响应
|
||
|
func NewErrorResponse(message string) gin.H {
|
||
|
return gin.H{
|
||
|
"success": false,
|
||
|
"message": message,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// NewPaginationResponse 创建分页响应
|
||
|
func NewPaginationResponse(data interface{}, total int64, page, pageSize int) gin.H {
|
||
|
return gin.H{
|
||
|
"success": true,
|
||
|
"data": data,
|
||
|
"total": total,
|
||
|
"page": page,
|
||
|
"pageSize": pageSize,
|
||
|
}
|
||
|
}
|