大面积重构
Response部分 usersController部分 中间件部分
This commit is contained in:
@@ -2,6 +2,7 @@ package dto
|
||||
|
||||
import (
|
||||
"drive-linked/pkg/serializer"
|
||||
"github.com/kataras/golog"
|
||||
"github.com/kataras/iris/v12"
|
||||
"net/http"
|
||||
)
|
||||
@@ -10,21 +11,18 @@ type Response struct {
|
||||
Ctx iris.Context
|
||||
}
|
||||
|
||||
const errJsonUnmarshalMsg = "{\"code\":500,\"msg\":\"Json解析错误,请联系管理员\",\"data\":null}"
|
||||
|
||||
func NewResponse(ctx iris.Context) *Response {
|
||||
return &Response{Ctx: ctx}
|
||||
}
|
||||
|
||||
const errJsonUnmarshalMsg = "{\"code\":500,\"msg\":\"Json解析错误,请联系管理员\",\"data\":null}"
|
||||
|
||||
// 成功 统一处理
|
||||
func (r *Response) Success(data interface{}) {
|
||||
res := serializer.Response{
|
||||
Code: 200,
|
||||
Msg: "",
|
||||
Data: data,
|
||||
}
|
||||
_, err := r.Ctx.JSON(res)
|
||||
resp := serializer.ResponseSerial{Code: http.StatusOK, Data: data}
|
||||
_, err := r.Ctx.JSON(resp)
|
||||
if err != nil {
|
||||
golog.Error("Json解析错误: ", resp)
|
||||
r.Ctx.Write([]byte(errJsonUnmarshalMsg))
|
||||
return
|
||||
}
|
||||
@@ -32,12 +30,8 @@ func (r *Response) Success(data interface{}) {
|
||||
|
||||
// 失败 统一处理
|
||||
func (r *Response) Error(code int, msg string) {
|
||||
res := serializer.Response{
|
||||
Code: code,
|
||||
Msg: msg,
|
||||
Data: nil,
|
||||
}
|
||||
_, err := r.Ctx.JSON(res)
|
||||
resp := serializer.ResponseSerial{Code: code, Msg: msg}
|
||||
_, err := r.Ctx.JSON(resp)
|
||||
if err != nil {
|
||||
r.Ctx.Write([]byte(errJsonUnmarshalMsg))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user