response.go 515 B

123456789101112131415161718192021222324252627282930
  1. package app
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "kpt.xdmy/pkg/e"
  5. )
  6. type Gin struct {
  7. C *gin.Context
  8. }
  9. func (g *Gin) Response(httpCode, errCode int, data interface{}) {
  10. g.C.JSON(httpCode, gin.H{
  11. "code": httpCode,
  12. "msg": e.GetMsg(errCode),
  13. "data": data,
  14. })
  15. return
  16. }
  17. func (g *Gin) ResponseEq(httpCode, errCode int, errorNo int, data interface{}) {
  18. g.C.JSON(httpCode, gin.H{
  19. "code": httpCode,
  20. "message": e.GetMsg(errCode),
  21. "results": data,
  22. "errorNo": errorNo,
  23. "success": 1,
  24. })
  25. return
  26. }