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) }