1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package e
- import (
- "github.com/gin-gonic/gin"
- "net/http"
- "project_management/unity"
- )
- type R struct {
- Code Rescode `json:"code"`
- Message any `json:"message"`
- Data interface{} `json:"data"`
- }
- func ResponseError(c *gin.Context, code Rescode) {
- c.JSON(http.StatusOK, &R{
- Code: code,
- Message: code.GetMsg(),
- Data: nil,
- })
- }
- func ResponseSuccess(c *gin.Context, data interface{}) {
- c.JSON(http.StatusOK, &R{
- Code: SUCCESS,
- Message: SUCCESS.GetMsg(),
- Data: data,
- })
- }
- func ResponseWithMsg(c *gin.Context, code Rescode, msg any) {
- c.JSON(http.StatusOK, &R{
- Code: code,
- Message: msg,
- Data: nil,
- })
- }
- func ResPonsePage(c *gin.Context, data interface{}, total int64, params unity.QueryPageParams) {
- c.JSON(http.StatusOK, &R{
- Code: SUCCESS,
- Message: SUCCESS.GetMsg(),
- Data: gin.H{
- "result": data,
- "total": total,
- "current": params.Page,
- "page_size": params.Size,
- },
- })
- }
- func CapResPonsePage(c *gin.Context, data interface{}, total int64, params unity.CapQueryPageParams) {
- c.JSON(http.StatusOK, &R{
- Code: SUCCESS,
- Message: SUCCESS.GetMsg(),
- Data: gin.H{
- "result": data,
- "total": total,
- "current": params.Page,
- "page_size": params.Size,
- },
- })
- }
|