improve function *Struct for ghttp.Request

This commit is contained in:
Jack
2020-08-13 18:51:59 +08:00
parent 84d761b418
commit 820e4302b7
3 changed files with 13 additions and 2 deletions

View File

@ -189,6 +189,9 @@ func (r *Request) GetFormMapStrVar(kvMap ...map[string]interface{}) map[string]*
// The optional parameter <mapping> is used to specify the key to attribute mapping.
func (r *Request) GetFormStruct(pointer interface{}, mapping ...map[string]string) error {
r.parseForm()
if len(r.formMap) == 0 {
return nil
}
return gconv.StructDeep(r.formMap, pointer, mapping...)
}

View File

@ -193,7 +193,11 @@ func (r *Request) GetQueryMapStrVar(kvMap ...map[string]interface{}) map[string]
// attribute mapping.
func (r *Request) GetQueryStruct(pointer interface{}, mapping ...map[string]string) error {
r.parseQuery()
return gconv.StructDeep(r.GetQueryMap(), pointer, mapping...)
m := r.GetQueryMap()
if len(m) == 0 {
return nil
}
return gconv.StructDeep(m, pointer, mapping...)
}
// GetQueryToStruct is alias of GetQueryStruct. See GetQueryStruct.

View File

@ -267,7 +267,11 @@ func (r *Request) GetRequestMapStrVar(kvMap ...map[string]interface{}) map[strin
// the parameter <pointer> is a pointer to the struct object.
// The optional parameter <mapping> is used to specify the key to attribute mapping.
func (r *Request) GetRequestStruct(pointer interface{}, mapping ...map[string]string) error {
return gconv.StructDeep(r.GetRequestMap(), pointer, mapping...)
m := r.GetRequestMap()
if len(m) == 0 {
return nil
}
return gconv.StructDeep(m, pointer, mapping...)
}
// GetRequestToStruct is alias of GetRequestStruct. See GetRequestStruct.