From a31b7df283c389adc70f47c6d6083494253986ee Mon Sep 17 00:00:00 2001 From: "pzrr@qq.com" Date: Mon, 8 Jan 2018 11:53:27 +0800 Subject: [PATCH] =?UTF-8?q?####=20Version=201.4.4=20*=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?Bind=E6=A8=A1=E5=9D=97=E5=86=85=E9=83=A8=E8=8E=B7=E5=8F=96req.B?= =?UTF-8?q?ody=E4=B8=BAHttpContext.PostBody,=E9=81=BF=E5=85=8D=E5=9B=A0?= =?UTF-8?q?=E4=B8=BABind=E5=90=8E=E6=97=A0=E6=B3=95=E5=86=8D=E6=AC=A1?= =?UTF-8?q?=E8=8E=B7=E5=8F=96Post=E5=86=85=E5=AE=B9=20*=20=E5=AE=8C?= =?UTF-8?q?=E5=96=84debug=20log=20=E8=BE=93=E5=87=BA=20*=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0example/static,=20=E8=AF=A5=E7=A4=BA=E4=BE=8B=E7=9B=AE?= =?UTF-8?q?=E5=89=8D=E4=B8=BA=E5=AE=9E=E7=8E=B0=E4=B8=80=E4=B8=AA=E7=BA=AF?= =?UTF-8?q?=E9=9D=99=E6=80=81=E6=96=87=E4=BB=B6=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=20*=20*=202018-01-08=2012:00?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bind.go | 9 ++++----- example/static/main.go | 14 ++------------ version.MD | 6 ++++++ 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/bind.go b/bind.go index d21a656..a136617 100644 --- a/bind.go +++ b/bind.go @@ -34,9 +34,9 @@ func (b *binder) Bind(i interface{}, ctx Context) (err error) { err = errors.New("request unsupported MediaType -> " + ctype) switch { case strings.HasPrefix(ctype, MIMEApplicationJSON): - err = json.NewDecoder(req.Body).Decode(i) + err = json.Unmarshal(ctx.Request().PostBody(), i) case strings.HasPrefix(ctype, MIMEApplicationXML): - err = xml.NewDecoder(req.Body).Decode(i) + err = xml.Unmarshal(ctx.Request().PostBody(), i) //case strings.HasPrefix(ctype, MIMEApplicationForm), strings.HasPrefix(ctype, MIMEMultipartForm), // strings.HasPrefix(ctype, MIMETextHTML): // err = reflects.ConvertMapToStruct(defaultTagName, i, ctx.FormValues()) @@ -54,12 +54,11 @@ func (b *binder) Bind(i interface{}, ctx Context) (err error) { //BindJsonBody default use json decode req.Body to struct func (b *binder) BindJsonBody(i interface{}, ctx Context) (err error) { - req := ctx.Request() - if req.Body == nil { + if ctx.Request().PostBody() == nil { err = errors.New("request body can't be empty") return err } - err = json.NewDecoder(req.Body).Decode(i) + err = json.Unmarshal(ctx.Request().PostBody(), i) return err } diff --git a/example/static/main.go b/example/static/main.go index 475dc5b..daeab73 100644 --- a/example/static/main.go +++ b/example/static/main.go @@ -19,22 +19,12 @@ func main() { //设置路由 InitRoute(app.HttpServer) - //启动 监控服务 - //app.SetPProfConfig(true, 8081) - // 开始服务 - port := 8080 + port := 80 fmt.Println("dotweb.StartServer => " + strconv.Itoa(port)) err := app.StartServer(port) fmt.Println("dotweb.StartServer error => ", err) } - -func Index(ctx dotweb.Context) error { - ctx.Response().Header().Set("Content-Type", "text/html; charset=utf-8") - return ctx.WriteString("index") -} - func InitRoute(server *dotweb.HttpServer) { - server.Router().GET("/", Index) - server.Router().ServerFile("/static/*filepath", "d:/gotmp") + server.Router().ServerFile("/*filepath", "/devfeel/dotweb/public") } diff --git a/version.MD b/version.MD index 4baa3eb..6cccea7 100644 --- a/version.MD +++ b/version.MD @@ -1,5 +1,11 @@ ## dotweb版本记录: +#### Version 1.4.4 +* 调整Bind模块内部获取req.Body为HttpContext.PostBody,避免因为Bind后无法再次获取Post内容 +* 完善debug log 输出 +* 更新example/static, 该示例目前为实现一个纯静态文件服务器功能 +* * 2018-01-08 12:00 + #### Version 1.4.3 * 调整dotweb内部路由注册逻辑,New模式默认不开启,Classic模式默认开启,可通过app.UseDotwebRouter手动开启 * 修复 issue #100, 解决特定场景下Exclude不生效问题