1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package e
- import (
- "Ic_ouath/page"
- "github.com/gin-gonic/gin"
- "net/http"
- )
- 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 page.PageParams) {
- c.JSON(http.StatusOK, &R{
- Code: SUCCESS,
- Message: SUCCESS.GetMsg(),
- Data: gin.H{
- "result": data,
- "total": total,
- "page": params.Page,
- "page_size": params.Size,
- },
- })
- }
|