common.go 567 B

12345678910111213141516171819202122232425
  1. package controller
  2. import "github.com/gin-gonic/gin"
  3. type JsonStruct struct {
  4. Code int `json:"code"`
  5. Msg interface{} `json:"msg"`
  6. Data interface{} `json:"data"`
  7. //Count int64 `json:"count"`
  8. }
  9. type JsonErrStruct struct {
  10. Code int `json:"code"`
  11. Msg interface{} `json:"msg"`
  12. }
  13. func returnSuccess(c *gin.Context, code int, data interface{}) {
  14. json := &JsonStruct{Code: code, Msg: "ok", Data: data}
  15. c.JSON(200, json)
  16. }
  17. func returnError(c *gin.Context, code int) {
  18. json := &JsonErrStruct{Code: code, Msg: "error"}
  19. c.JSON(400, json)
  20. }