123456789101112131415161718192021222324252627282930 |
- package controller
- import "github.com/gin-gonic/gin"
- type JsonStruct struct {
- Code int `json:"code"`
- Msg interface{} `json:"msg"`
- Data interface{} `json:"data"`
- //Count int64 `json:"count"`
- }
- type JsonErrStruct struct {
- Code int `json:"code"`
- Msg interface{} `json:"msg"`
- }
- func returnSuccess(c *gin.Context, code int, data interface{}) {
- json := &JsonStruct{Code: code, Msg: "ok", Data: data}
- c.JSON(200, json)
- }
- func returnError(c *gin.Context, code int, msg string) {
- json := &JsonErrStruct{}
- if msg == "" {
- json = &JsonErrStruct{Code: code, Msg: "error"}
- } else {
- json = &JsonErrStruct{Code: code, Msg: msg}
- }
- c.JSON(400, json)
- }
|