R.go 934 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package e
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "lot_interlligentControl/unity"
  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.PageParams) {
  34. c.JSON(http.StatusOK, &R{
  35. Code: SUCCESS,
  36. Message: SUCCESS.GetMsg(),
  37. Data: gin.H{
  38. "result": data,
  39. "total": total,
  40. "page_size": params.Size,
  41. },
  42. })
  43. }