R.go 962 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package e
  2. import (
  3. "Panel_development/unity"
  4. "github.com/gin-gonic/gin"
  5. "net/http"
  6. )
  7. type R struct {
  8. Code Rescode `json:"code"`
  9. Message any `json:"message"`
  10. Data interface{} `json:"data"`
  11. }
  12. func ResponseError(c *gin.Context, code Rescode) {
  13. c.JSON(http.StatusOK, &R{
  14. Code: code,
  15. Message: code.GetMsg(),
  16. Data: nil,
  17. })
  18. }
  19. func ResponseSuccess(c *gin.Context, data interface{}) {
  20. c.JSON(http.StatusOK, &R{
  21. Code: SUCCESS,
  22. Message: SUCCESS.GetMsg(),
  23. Data: data,
  24. })
  25. }
  26. func ResponseWithMsg(c *gin.Context, code Rescode, msg any) {
  27. c.JSON(http.StatusOK, &R{
  28. Code: code,
  29. Message: msg,
  30. Data: nil,
  31. })
  32. }
  33. func ResPonsePage(c *gin.Context, data interface{}, total int64, params unity.QueryPageParams) {
  34. c.JSON(http.StatusOK, &R{
  35. Code: SUCCESS,
  36. Message: SUCCESS.GetMsg(),
  37. Data: gin.H{
  38. "result": data,
  39. "total": total,
  40. "current": params.Page,
  41. "page_size": params.Size,
  42. },
  43. })
  44. }