improve *Struct functions for ghttp.Request

This commit is contained in:
Jack
2020-08-13 23:29:00 +08:00
parent 875d2b7e63
commit 737af527cd
5 changed files with 18 additions and 18 deletions

View File

@ -11,7 +11,7 @@ please note your github/gitee account in your payment bill. All the donations wi
| Name | Channel | Amount | Comment
|---|---|--- | ---
|[hailaz](https://gitee.com/hailaz)|gitee|¥20.00 |
|[ireadx](https://github.com/ireadx)|alipay|¥301.00 |
|[ireadx](https://github.com/ireadx)|alipay|¥501.00 |
|[mg91](https://gitee.com/mg91)|gitee|¥10.00 |
|[pibigstar](https://github.com/pibigstar)|alipay|¥10.00 |
|[tiangenglan](https://gitee.com/tiangenglan)|gitee|¥30.00 |
@ -115,7 +115,6 @@ please note your github/gitee account in your payment bill. All the donations wi
|(hyuant)[https://github.com/hyuant]|alipay|¥66.66|
|*庆|alipay|¥9.99| 支持一下gf越来越好
|**君|alipay|¥10.00| 加油
|闫沧|alipay|¥200.00| gf越来越强

View File

@ -66,9 +66,9 @@ CREATE TABLE %s (
Address string `json:"address"`
}
type EntityUserScores struct {
Id int `json:"id"`
Uid int `json:"uid"`
Score int `json:"score"`
Id int `json:"id"`
UserId int `json:"uid"`
Score int `json:"score"`
}
type Entity struct {
User *EntityUser
@ -144,10 +144,10 @@ CREATE TABLE %s (
t.Assert(err, nil)
t.Assert(len(users[0].UserScores), 5)
t.Assert(len(users[1].UserScores), 5)
t.Assert(users[0].UserScores[0].Uid, 3)
t.Assert(users[0].UserScores[0].UserId, 3)
t.Assert(users[0].UserScores[0].Score, 1)
t.Assert(users[0].UserScores[4].Score, 5)
t.Assert(users[1].UserScores[0].Uid, 4)
t.Assert(users[1].UserScores[0].UserId, 4)
t.Assert(users[1].UserScores[0].Score, 1)
t.Assert(users[1].UserScores[4].Score, 5)
})
@ -177,10 +177,10 @@ CREATE TABLE %s (
t.Assert(err, nil)
t.Assert(len(users[0].UserScores), 5)
t.Assert(len(users[1].UserScores), 5)
t.Assert(users[0].UserScores[0].Uid, 3)
t.Assert(users[0].UserScores[0].UserId, 3)
t.Assert(users[0].UserScores[0].Score, 1)
t.Assert(users[0].UserScores[4].Score, 5)
t.Assert(users[1].UserScores[0].Uid, 4)
t.Assert(users[1].UserScores[0].UserId, 4)
t.Assert(users[1].UserScores[0].Score, 1)
t.Assert(users[1].UserScores[4].Score, 5)
})
@ -319,10 +319,10 @@ CREATE TABLE %s (
t.Assert(len(users[0].UserScores), 5)
t.Assert(len(users[1].UserScores), 5)
t.Assert(users[0].UserScores[0].Uid, 3)
t.Assert(users[0].UserScores[0].UserId, 3)
t.Assert(users[0].UserScores[0].Score, 1)
t.Assert(users[0].UserScores[4].Score, 5)
t.Assert(users[1].UserScores[0].Uid, 4)
t.Assert(users[1].UserScores[0].UserId, 4)
t.Assert(users[1].UserScores[0].Score, 1)
t.Assert(users[1].UserScores[4].Score, 5)
})

View File

@ -189,10 +189,11 @@ 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
m := r.formMap
if m == nil {
m = map[string]interface{}{}
}
return gconv.StructDeep(r.formMap, pointer, mapping...)
return gconv.StructDeep(m, pointer, mapping...)
}
// GetFormToStruct is alias of GetFormStruct. See GetFormStruct.

View File

@ -194,8 +194,8 @@ func (r *Request) GetQueryMapStrVar(kvMap ...map[string]interface{}) map[string]
func (r *Request) GetQueryStruct(pointer interface{}, mapping ...map[string]string) error {
r.parseQuery()
m := r.GetQueryMap()
if len(m) == 0 {
return nil
if m == nil {
m = map[string]interface{}{}
}
return gconv.StructDeep(m, pointer, mapping...)
}

View File

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