response.go 490 B

1234567891011121314151617181920212223242526272829
  1. package app
  2. import (
  3. "mtp2_if/global/e"
  4. "github.com/gin-gonic/gin"
  5. )
  6. // Gin is gin.Context
  7. type Gin struct {
  8. C *gin.Context
  9. }
  10. // Response 通用Response数据结构
  11. type Response struct {
  12. Code int `json:"code"`
  13. Msg string `json:"msg"`
  14. Data interface{} `json:"data"`
  15. }
  16. // Response setting gin.JSON
  17. func (g *Gin) Response(httpCode, errCode int, data interface{}) {
  18. g.C.JSON(httpCode, Response{
  19. Code: errCode,
  20. Msg: e.GetMsg(errCode),
  21. Data: data,
  22. })
  23. return
  24. }