package ginhelper import ( "log" "net/http" "github.com/gin-gonic/gin" ) const MessageSuccess="success" type Response struct { Code int `json:"code"` Message string `json:"message"` Data interface{} `json:"data"` } func Success(c *gin.Context, data interface{}){ c.JSON(http.StatusOK, &Response{Code: 0, Message: MessageSuccess, Data: data, }) } func Error(c *gin.Context, code int, err error){ c.JSON(http.StatusOK, &Response{Code: code, Message: err.Error(), Data: nil}) } func ErrorWithLog(c *gin.Context, code int, err error){ log.Println(err) Error(c, code, err) }