enhance(response):更新基本的简易响应生成函数。
This commit is contained in:
parent
7a55b78ebe
commit
2281ebe00b
|
@ -19,10 +19,58 @@ func NewResult(ctx *gin.Context) *Result {
|
||||||
return &Result{Ctx: ctx}
|
return &Result{Ctx: ctx}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 统一出错信息
|
// 操作出错(未成功)响应
|
||||||
func (r *Result) Error(code int, msg string) {
|
func (r *Result) Error(code int, msg string) {
|
||||||
res := BaseResponse{}
|
res := BaseResponse{}
|
||||||
res.Code = code
|
res.Code = code
|
||||||
res.Message = msg
|
res.Message = msg
|
||||||
|
r.Ctx.JSON(http.StatusInternalServerError, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 简易操作成功信息
|
||||||
|
func (r *Result) Success(msg string) {
|
||||||
|
res := BaseResponse{}
|
||||||
|
res.Code = http.StatusOK
|
||||||
|
res.Message = msg
|
||||||
r.Ctx.JSON(http.StatusOK, res)
|
r.Ctx.JSON(http.StatusOK, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 数据成功创建
|
||||||
|
func (r *Result) Created(msg string) {
|
||||||
|
res := BaseResponse{}
|
||||||
|
res.Code = http.StatusCreated
|
||||||
|
res.Message = msg
|
||||||
|
r.Ctx.JSON(http.StatusCreated, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 数据成功更新
|
||||||
|
func (r *Result) Updated(msg string) {
|
||||||
|
res := BaseResponse{}
|
||||||
|
res.Code = http.StatusAccepted
|
||||||
|
res.Message = msg
|
||||||
|
r.Ctx.JSON(http.StatusAccepted, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 数据已成功删除
|
||||||
|
func (r *Result) Deleted(msg string) {
|
||||||
|
res := BaseResponse{}
|
||||||
|
res.Code = http.StatusNoContent
|
||||||
|
res.Message = msg
|
||||||
|
r.Ctx.JSON(http.StatusNoContent, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 指定操作未被接受
|
||||||
|
func (r *Result) NotAccept(msg string) {
|
||||||
|
res := BaseResponse{}
|
||||||
|
res.Code = http.StatusNotAcceptable
|
||||||
|
res.Message = msg
|
||||||
|
r.Ctx.JSON(http.StatusNotAcceptable, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 数据未找到
|
||||||
|
func (r *Result) NotFound(msg string) {
|
||||||
|
res := BaseResponse{}
|
||||||
|
res.Code = http.StatusNotFound
|
||||||
|
res.Message = msg
|
||||||
|
r.Ctx.JSON(http.StatusNotFound, res)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user