R.go 633 B

12345678910111213141516171819202122232425262728293031323334
  1. package e
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "net/http"
  5. )
  6. type R struct {
  7. Code Rescode `json:"code"`
  8. Message any `json:"message"`
  9. Data interface{} `json:"data"`
  10. }
  11. func ResponseError(c *gin.Context, code Rescode) {
  12. c.JSON(http.StatusOK, &R{
  13. Code: code,
  14. Message: code.GetMsg(),
  15. Data: nil,
  16. })
  17. }
  18. func ResponseSuccess(c *gin.Context, data interface{}) {
  19. c.JSON(http.StatusOK, &R{
  20. Code: SUCCESS,
  21. Message: SUCCESS.GetMsg(),
  22. Data: data,
  23. })
  24. }
  25. func ResponseWithMsg(c *gin.Context, code Rescode, msg any) {
  26. c.JSON(http.StatusOK, &R{
  27. Code: code,
  28. Message: msg,
  29. Data: nil,
  30. })
  31. }