正在显示
3 个修改的文件
包含
20 行增加
和
3 行删除
| @@ -2,14 +2,13 @@ package appsvr | @@ -2,14 +2,13 @@ package appsvr | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "github.com/astaxie/beego" | 4 | "github.com/astaxie/beego" |
| 5 | - "github.com/linmadan/egglib-go/web/beego/filters" | ||
| 6 | . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" | 5 | . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" |
| 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/middleware" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/middleware" |
| 8 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/routers" | 7 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/routers" |
| 9 | ) | 8 | ) |
| 10 | 9 | ||
| 11 | func init() { | 10 | func init() { |
| 12 | - beego.InsertFilter("/*", beego.BeforeExec, filters.CreateRequestBodyFilter()) | 11 | + beego.InsertFilter("/*", beego.BeforeExec, middleware.CreateRequestBodyFilter()) |
| 13 | beego.InsertFilter("/*", beego.BeforeExec, middleware.CreateRequstLogFilter(Logger)) | 12 | beego.InsertFilter("/*", beego.BeforeExec, middleware.CreateRequstLogFilter(Logger)) |
| 14 | beego.InsertFilter("/*", beego.AfterExec, middleware.CreateResponseLogFilter(Logger), false) | 13 | beego.InsertFilter("/*", beego.AfterExec, middleware.CreateResponseLogFilter(Logger), false) |
| 15 | } | 14 | } |
| @@ -20,7 +20,7 @@ func (this *UserController) UserInfo() { | @@ -20,7 +20,7 @@ func (this *UserController) UserInfo() { | ||
| 20 | }() | 20 | }() |
| 21 | var request *protocol.UserInfoRequest | 21 | var request *protocol.UserInfoRequest |
| 22 | if err := this.JsonUnmarshal(&request); err != nil { | 22 | if err := this.JsonUnmarshal(&request); err != nil { |
| 23 | - msg = protocol.BadRequestParam(1) | 23 | + msg = protocol.BadRequestParam(2) |
| 24 | return | 24 | return |
| 25 | } | 25 | } |
| 26 | if b, m := this.Valid(request); !b { | 26 | if b, m := this.Valid(request); !b { |
| @@ -5,6 +5,7 @@ import ( | @@ -5,6 +5,7 @@ import ( | ||
| 5 | "fmt" | 5 | "fmt" |
| 6 | "github.com/astaxie/beego/context" | 6 | "github.com/astaxie/beego/context" |
| 7 | "github.com/astaxie/beego/logs" | 7 | "github.com/astaxie/beego/logs" |
| 8 | + "io/ioutil" | ||
| 8 | "time" | 9 | "time" |
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| @@ -30,3 +31,20 @@ func CreateResponseLogFilter(logger *logs.BeeLogger) func(ctx *context.Context) | @@ -30,3 +31,20 @@ func CreateResponseLogFilter(logger *logs.BeeLogger) func(ctx *context.Context) | ||
| 30 | logger.Debug(fmt.Sprintf("<====Send RequestId:%v BodyData:%s", requestId, body)) | 31 | logger.Debug(fmt.Sprintf("<====Send RequestId:%v BodyData:%s", requestId, body)) |
| 31 | } | 32 | } |
| 32 | } | 33 | } |
| 34 | + | ||
| 35 | +func CreateRequestBodyFilter() func(ctx *context.Context) { | ||
| 36 | + return func(ctx *context.Context) { | ||
| 37 | + if len(ctx.Input.RequestBody) == 0 { | ||
| 38 | + if ctx.Request.Method == "POST" || ctx.Request.Method == "PUT" { | ||
| 39 | + body, _ := ioutil.ReadAll(ctx.Request.Body) | ||
| 40 | + if len(body) == 0 { | ||
| 41 | + body = []byte("{}") | ||
| 42 | + } | ||
| 43 | + ctx.Input.SetData("requestBody", body) | ||
| 44 | + ctx.Request.Body.Close() | ||
| 45 | + } | ||
| 46 | + } else { | ||
| 47 | + ctx.Input.SetData("requestBody", ctx.Input.RequestBody) | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | +} |
-
请 注册 或 登录 后发表评论