Skip to content

Commit 7ec5535

Browse files
authored
Merge pull request devfeel#102 from devfeel/develop
Version 1.4.4 - 调整Bind模块实现,完善日志,增加纯静态文件服务器示例
2 parents 34f6a50 + a31b7df commit 7ec5535

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

bind.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ func (b *binder) Bind(i interface{}, ctx Context) (err error) {
3434
err = errors.New("request unsupported MediaType -> " + ctype)
3535
switch {
3636
case strings.HasPrefix(ctype, MIMEApplicationJSON):
37-
err = json.NewDecoder(req.Body).Decode(i)
37+
err = json.Unmarshal(ctx.Request().PostBody(), i)
3838
case strings.HasPrefix(ctype, MIMEApplicationXML):
39-
err = xml.NewDecoder(req.Body).Decode(i)
39+
err = xml.Unmarshal(ctx.Request().PostBody(), i)
4040
//case strings.HasPrefix(ctype, MIMEApplicationForm), strings.HasPrefix(ctype, MIMEMultipartForm),
4141
// strings.HasPrefix(ctype, MIMETextHTML):
4242
// err = reflects.ConvertMapToStruct(defaultTagName, i, ctx.FormValues())
@@ -54,12 +54,11 @@ func (b *binder) Bind(i interface{}, ctx Context) (err error) {
5454

5555
//BindJsonBody default use json decode req.Body to struct
5656
func (b *binder) BindJsonBody(i interface{}, ctx Context) (err error) {
57-
req := ctx.Request()
58-
if req.Body == nil {
57+
if ctx.Request().PostBody() == nil {
5958
err = errors.New("request body can't be empty")
6059
return err
6160
}
62-
err = json.NewDecoder(req.Body).Decode(i)
61+
err = json.Unmarshal(ctx.Request().PostBody(), i)
6362
return err
6463
}
6564

example/static/main.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,12 @@ func main() {
1919
//设置路由
2020
InitRoute(app.HttpServer)
2121

22-
//启动 监控服务
23-
//app.SetPProfConfig(true, 8081)
24-
2522
// 开始服务
26-
port := 8080
23+
port := 80
2724
fmt.Println("dotweb.StartServer => " + strconv.Itoa(port))
2825
err := app.StartServer(port)
2926
fmt.Println("dotweb.StartServer error => ", err)
3027
}
31-
32-
func Index(ctx dotweb.Context) error {
33-
ctx.Response().Header().Set("Content-Type", "text/html; charset=utf-8")
34-
return ctx.WriteString("index")
35-
}
36-
3728
func InitRoute(server *dotweb.HttpServer) {
38-
server.Router().GET("/", Index)
39-
server.Router().ServerFile("/static/*filepath", "d:/gotmp")
29+
server.Router().ServerFile("/*filepath", "/devfeel/dotweb/public")
4030
}

version.MD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## dotweb版本记录:
22

3+
#### Version 1.4.4
4+
* 调整Bind模块内部获取req.Body为HttpContext.PostBody,避免因为Bind后无法再次获取Post内容
5+
* 完善debug log 输出
6+
* 更新example/static, 该示例目前为实现一个纯静态文件服务器功能
7+
* * 2018-01-08 12:00
8+
39
#### Version 1.4.3
410
* 调整dotweb内部路由注册逻辑,New模式默认不开启,Classic模式默认开启,可通过app.UseDotwebRouter手动开启
511
* 修复 issue #100, 解决特定场景下Exclude不生效问题

0 commit comments

Comments
 (0)