feat: article: finish base functions

This commit is contained in:
fallen-angle
2022-02-15 16:49:32 +08:00
parent 72ef5c92c4
commit be5def58fd
13 changed files with 245 additions and 37 deletions

View File

@@ -7,7 +7,14 @@ import (
"github.com/gin-gonic/gin"
)
func Success(c *gin.Context, code int, msg interface{}, data interface{}) {
const (
SUCCESS = "Success"
BAD_REQUEST = "Bad Request"
DATA_NOT_FOUND = "Data not Found"
STATUS_DATA_NOT_FOUND = 210
)
func Success(c *gin.Context, status int, code int, msg interface{}, data interface{}) {
c.JSON(http.StatusOK, models.GinResponse{Code: code, Msg: msg, Data: data})
}
@@ -16,9 +23,29 @@ func Error(c *gin.Context, status int, code int, msg interface{}, data interface
}
func Succ(c *gin.Context, data interface{}) {
Success(c, http.StatusOK, "success", data)
Success(c, http.StatusOK, http.StatusOK, SUCCESS, data)
}
func DataNotFound(c *gin.Context, data interface{}) {
Success(c, http.StatusOK, STATUS_DATA_NOT_FOUND, DATA_NOT_FOUND, data)
}
func Err(c *gin.Context, status int, code int, msg interface{}) {
c.JSON(status, models.GinResponse{Code: code, Msg: msg})
Error(c, status, code, msg, nil)
}
func ServerError(c *gin.Context, code int, msg interface{}) {
Err(c, http.StatusInternalServerError, code, msg)
}
func ServerErr(c *gin.Context, msg interface{}) {
ServerError(c, http.StatusInternalServerError, msg)
}
func RequestError(c *gin.Context, code int, data interface{}) {
Error(c, http.StatusBadRequest, code, BAD_REQUEST, data)
}
func RequestErr(c *gin.Context, data interface{}) {
RequestError(c, http.StatusBadRequest, data)
}