From f775479c3f5a74cb87ea0d5a1ccbd45a5fb11415 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 5 Dec 2019 10:44:31 +0800 Subject: [PATCH] fix issue in ghttp.Request.GetRequest* --- .example/other/test.go | 31 ++---------------------- RELEASE.2.MD | 2 +- net/ghttp/ghttp_request_param_request.go | 10 ++++---- 3 files changed, 8 insertions(+), 35 deletions(-) diff --git a/.example/other/test.go b/.example/other/test.go index 69aa55a6b..16865105d 100644 --- a/.example/other/test.go +++ b/.example/other/test.go @@ -1,42 +1,15 @@ package main import ( - "net/http" - "github.com/gogf/gf/frame/g" "github.com/gogf/gf/net/ghttp" ) -func MiddlewareAuth(r *ghttp.Request) { - token := r.Get("token") - if token == "123456" { - r.Middleware.Next() - } else { - r.Response.WriteStatus(http.StatusForbidden) - } -} - -func MiddlewareCORS(r *ghttp.Request) { - r.Response.CORSDefault() - r.Middleware.Next() -} - -func MiddlewareLog(r *ghttp.Request) { - r.Middleware.Next() - g.Log().Println(r.Response.Status, r.URL.Path, r.GetError().Error()) -} - func main() { s := g.Server() - s.SetConfigWithMap(g.Map{ - "AccessLogEnabled": false, - "ErrorLogEnabled": false, - }) - s.BindMiddlewareDefault(MiddlewareLog) s.Group("/api.v2", func(group *ghttp.RouterGroup) { - group.Middleware(MiddlewareAuth, MiddlewareCORS) - group.ALL("/user/list", func(r *ghttp.Request) { - panic("啊!我出错了!") + group.ALL("/test", func(r *ghttp.Request) { + r.Response.Write(r.GetRequest("nickname")) }) }) s.SetPort(8199) diff --git a/RELEASE.2.MD b/RELEASE.2.MD index 35f9e0488..55008ebb7 100644 --- a/RELEASE.2.MD +++ b/RELEASE.2.MD @@ -1,4 +1,4 @@ -# `v1.9.3` +# `v1.9.3` (2019-09-24) 该版本实际为`v2.0`的大版本发布,为避免`go module`机制严格要求`v2`版本以上需要修改`import`并加上`v2`后缀,因此使用了`v1.9`版本进行发布。 diff --git a/net/ghttp/ghttp_request_param_request.go b/net/ghttp/ghttp_request_param_request.go index 472edb56e..da528675c 100644 --- a/net/ghttp/ghttp_request_param_request.go +++ b/net/ghttp/ghttp_request_param_request.go @@ -19,18 +19,18 @@ import ( // GetRequest is one of the most commonly used functions for retrieving parameters. // // Note that if there're multiple parameters with the same name, the parameters are retrieved and overwrote -// in order of priority: router < query < form < body < custom. +// in order of priority: router < query < body < form < custom. func (r *Request) GetRequest(key string, def ...interface{}) interface{} { value := r.GetParam(key) + if value == nil { + value = r.GetForm(key) + } if value == nil { r.ParseBody() if len(r.bodyMap) > 0 { value = r.bodyMap[key] } } - if value == nil { - value = r.GetForm(key) - } if value == nil { value = r.GetQuery(key) } @@ -166,7 +166,7 @@ func (r *Request) GetRequestInterfaces(key string, def ...interface{}) []interfa // GetRequestMap is one of the most commonly used functions for retrieving parameters. // // Note that if there're multiple parameters with the same name, the parameters are retrieved and overwrote -// in order of priority: router < query < form < body < custom. +// in order of priority: router < query < body < form < custom. func (r *Request) GetRequestMap(kvMap ...map[string]interface{}) map[string]interface{} { r.ParseQuery() r.ParseForm()