diff --git a/net/ghttp/ghttp_request.go b/net/ghttp/ghttp_request.go index dd7ccaece..d3ee68248 100644 --- a/net/ghttp/ghttp_request.go +++ b/net/ghttp/ghttp_request.go @@ -46,7 +46,7 @@ type Request struct { postMap map[string]interface{} // POST解析参数 deleteMap map[string]interface{} // DELETE解析参数 routerMap map[string]interface{} // 路由解析参数 - rawVarMap map[string]interface{} // 原始数据参数 + rawMap map[string]interface{} // 原始数据参数 error error // 当前请求执行错误 exit bool // 是否退出当前请求流程执行 params map[string]interface{} // 开发者自定义参数(请求流程中有效) diff --git a/net/ghttp/ghttp_request_method_delete.go b/net/ghttp/ghttp_request_method_delete.go index 26baef3b1..218bb824d 100644 --- a/net/ghttp/ghttp_request_method_delete.go +++ b/net/ghttp/ghttp_request_method_delete.go @@ -111,7 +111,7 @@ func (r *Request) GetDeleteInterfaces(key string, def ...interface{}) []interfac } // 获取指定键名的关联数组,并且给定当指定键名不存在时的默认值。 -// 当不指定键值对关联数组时,默认获取POST方式提交的所有的提交键值对数据。 +// 当不指定键值对关联数组时,默认获取DELETE方式提交的所有的提交键值对数据。 func (r *Request) GetDeleteMap(kvMap ...map[string]interface{}) map[string]interface{} { r.initDelete() if len(kvMap) > 0 { @@ -132,7 +132,7 @@ func (r *Request) GetDeleteMap(kvMap ...map[string]interface{}) map[string]inter func (r *Request) GetDeleteMapStrStr(kvMap ...map[string]interface{}) map[string]string { deleteMap := r.GetDeleteMap(kvMap...) if len(deleteMap) > 0 { - m := make(map[string]string) + m := make(map[string]string, len(deleteMap)) for k, v := range deleteMap { m[k] = gconv.String(v) } @@ -144,7 +144,7 @@ func (r *Request) GetDeleteMapStrStr(kvMap ...map[string]interface{}) map[string func (r *Request) GetDeleteMapStrVar(kvMap ...map[string]interface{}) map[string]*gvar.Var { deleteMap := r.GetDeleteMap(kvMap...) if len(deleteMap) > 0 { - m := make(map[string]*gvar.Var) + m := make(map[string]*gvar.Var, len(deleteMap)) for k, v := range deleteMap { m[k] = gvar.New(v) } diff --git a/net/ghttp/ghttp_request_method_post.go b/net/ghttp/ghttp_request_method_post.go index 830c0e578..46006ca4a 100644 --- a/net/ghttp/ghttp_request_method_post.go +++ b/net/ghttp/ghttp_request_method_post.go @@ -165,7 +165,7 @@ func (r *Request) GetPostMap(kvMap ...map[string]interface{}) map[string]interfa func (r *Request) GetPostMapStrStr(kvMap ...map[string]interface{}) map[string]string { postMap := r.GetPostMap(kvMap...) if len(postMap) > 0 { - m := make(map[string]string) + m := make(map[string]string, len(postMap)) for k, v := range postMap { m[k] = gconv.String(v) } @@ -177,7 +177,7 @@ func (r *Request) GetPostMapStrStr(kvMap ...map[string]interface{}) map[string]s func (r *Request) GetPostMapStrVar(kvMap ...map[string]interface{}) map[string]*gvar.Var { postMap := r.GetPostMap(kvMap...) if len(postMap) > 0 { - m := make(map[string]*gvar.Var) + m := make(map[string]*gvar.Var, len(postMap)) for k, v := range postMap { m[k] = gvar.New(v) } diff --git a/net/ghttp/ghttp_request_method_put.go b/net/ghttp/ghttp_request_method_put.go index a13467687..6f6498f94 100644 --- a/net/ghttp/ghttp_request_method_put.go +++ b/net/ghttp/ghttp_request_method_put.go @@ -110,7 +110,7 @@ func (r *Request) GetPutInterfaces(key string, def ...interface{}) []interface{} } // 获取指定键名的关联数组,并且给定当指定键名不存在时的默认值。 -// 当不指定键值对关联数组时,默认获取POST方式提交的所有的提交键值对数据。 +// 当不指定键值对关联数组时,默认获取PUT方式提交的所有的提交键值对数据。 func (r *Request) GetPutMap(kvMap ...map[string]interface{}) map[string]interface{} { r.initPut() if len(kvMap) > 0 { @@ -131,7 +131,7 @@ func (r *Request) GetPutMap(kvMap ...map[string]interface{}) map[string]interfac func (r *Request) GetPutMapStrStr(kvMap ...map[string]interface{}) map[string]string { putMap := r.GetPutMap(kvMap...) if len(putMap) > 0 { - m := make(map[string]string) + m := make(map[string]string, len(putMap)) for k, v := range putMap { m[k] = gconv.String(v) } @@ -143,7 +143,7 @@ func (r *Request) GetPutMapStrStr(kvMap ...map[string]interface{}) map[string]st func (r *Request) GetPutMapStrVar(kvMap ...map[string]interface{}) map[string]*gvar.Var { putMap := r.GetPutMap(kvMap...) if len(putMap) > 0 { - m := make(map[string]*gvar.Var) + m := make(map[string]*gvar.Var, len(putMap)) for k, v := range putMap { m[k] = gvar.New(v) } diff --git a/net/ghttp/ghttp_request_method_query.go b/net/ghttp/ghttp_request_method_query.go index e5ad83148..7e20de5f3 100644 --- a/net/ghttp/ghttp_request_method_query.go +++ b/net/ghttp/ghttp_request_method_query.go @@ -136,7 +136,7 @@ func (r *Request) GetQueryMap(kvMap ...map[string]interface{}) map[string]interf func (r *Request) GetQueryMapStrStr(kvMap ...map[string]interface{}) map[string]string { queryMap := r.GetQueryMap(kvMap...) if len(queryMap) > 0 { - m := make(map[string]string) + m := make(map[string]string, len(queryMap)) for k, v := range queryMap { m[k] = gconv.String(v) } @@ -148,7 +148,7 @@ func (r *Request) GetQueryMapStrStr(kvMap ...map[string]interface{}) map[string] func (r *Request) GetQueryMapStrVar(kvMap ...map[string]interface{}) map[string]*gvar.Var { queryMap := r.GetQueryMap(kvMap...) if len(queryMap) > 0 { - m := make(map[string]*gvar.Var) + m := make(map[string]*gvar.Var, len(queryMap)) for k, v := range queryMap { m[k] = gvar.New(v) } diff --git a/net/ghttp/ghttp_request_request.go b/net/ghttp/ghttp_request_request.go index e9b8e5404..76bb017c6 100644 --- a/net/ghttp/ghttp_request_request.go +++ b/net/ghttp/ghttp_request_request.go @@ -18,11 +18,11 @@ func (r *Request) initRaw() { if !r.parsedRaw { r.parsedRaw = true if raw := r.GetRawString(); len(raw) > 0 { - r.rawVarMap, _ = gstr.Parse(raw) + r.rawMap, _ = gstr.Parse(raw) } } - if r.rawVarMap == nil { - r.rawVarMap = make(map[string]interface{}) + if r.rawMap == nil { + r.rawMap = make(map[string]interface{}) } } @@ -44,7 +44,7 @@ func (r *Request) GetRequest(key string, def ...interface{}) interface{} { return v } r.initRaw() - v = r.rawVarMap[key] + v = r.rawMap[key] if v == nil && len(def) > 0 { return def[0] } @@ -117,20 +117,16 @@ func (r *Request) GetRequestInterfaces(key string, def ...interface{}) []interfa func (r *Request) GetRequestMap(kvMap ...map[string]interface{}) map[string]interface{} { r.initRaw() - m := r.rawVarMap + m := make(map[string]interface{}) if len(kvMap) > 0 { - m = make(map[string]interface{}) for k, defValue := range kvMap[0] { - if rawValue, ok := r.rawVarMap[k]; ok { + if rawValue, ok := r.rawMap[k]; ok { m[k] = rawValue } else { m[k] = defValue } } } - if m == nil { - m = make(map[string]interface{}) - } for k, v := range r.GetPostMap(kvMap...) { m[k] = v } diff --git a/util/gutil/gutil_map.go b/util/gutil/gutil_map.go new file mode 100644 index 000000000..2dcd162b1 --- /dev/null +++ b/util/gutil/gutil_map.go @@ -0,0 +1,17 @@ +// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +// Package gutil provides utility functions. +package gutil + +// CopyMap does memory from map to . +func CopyMap(data map[string]interface{}) (copy map[string]interface{}) { + copy = make(map[string]interface{}, len(data)) + for k, v := range data { + copy[k] = v + } + return +}