feat: article: finish base functions
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user