R.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package e
  2. import (
  3. "bigdata_archives/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. }
  45. func ResPonsePageTime(c *gin.Context, data interface{}, total int64, params unity.TimePageParams) {
  46. c.JSON(http.StatusOK, &R{
  47. Code: SUCCESS,
  48. Message: SUCCESS.GetMsg(),
  49. Data: gin.H{
  50. "result": data,
  51. "total": total,
  52. "current": params.Page,
  53. "page_size": params.Size,
  54. "startTime": params.StartTime,
  55. "endTime": params.EndTime,
  56. },
  57. })
  58. }