response.go 615 B

123456789101112131415161718192021222324252627282930313233
  1. package app
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/kptyun/KPTCOMM/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. "status": httpCode,
  13. "msg": e.GetMsg(errCode),
  14. "data": data,
  15. })
  16. return
  17. }
  18. func (g *Gin) ResponseEq(httpCode, errCode int, errorNo int, data interface{}) {
  19. g.C.JSON(httpCode, gin.H{
  20. "code": httpCode,
  21. "status": httpCode,
  22. "message": e.GetMsg(errCode),
  23. "msg": e.GetMsg(errCode),
  24. "results": data,
  25. "errorNo": errorNo,
  26. "success": 1,
  27. })
  28. return
  29. }