resp.go 586 B

123456789101112131415161718192021222324252627
  1. package util
  2. import (
  3. "net/http"
  4. "youngee_m_api/consts"
  5. "youngee_m_api/model/http_model"
  6. "github.com/gin-gonic/gin"
  7. )
  8. func PackErrorResp(c *gin.Context, status int32) {
  9. resp := http_model.CommonResponse{
  10. Status: status,
  11. Message: consts.GetErrorToast(status),
  12. Data: nil,
  13. }
  14. c.JSON(http.StatusOK, resp)
  15. }
  16. func HandlerPackErrorResp(resp *http_model.CommonResponse, status int32, message string) {
  17. resp.Status = status
  18. if message != consts.DefaultToast {
  19. resp.Message = message
  20. } else {
  21. resp.Message = consts.GetErrorToast(status)
  22. }
  23. }