mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 14:30:56 +00:00
Added support to parse slices of ints and strings in ParseForm func
This commit is contained in:
parent
f988f035e5
commit
0c31c2d689
@ -358,11 +358,32 @@ func ParseForm(form url.Values, obj interface{}) error {
|
|||||||
}
|
}
|
||||||
fieldV.Set(reflect.ValueOf(t))
|
fieldV.Set(reflect.ValueOf(t))
|
||||||
}
|
}
|
||||||
|
case reflect.Slice:
|
||||||
|
if fieldT.Type == sliceOfInts {
|
||||||
|
formVals := form[tag]
|
||||||
|
fieldV.Set(reflect.MakeSlice(reflect.SliceOf(reflect.TypeOf(int(1))), len(formVals), len(formVals)))
|
||||||
|
for i := 0; i < len(formVals); i++ {
|
||||||
|
val, err := strconv.Atoi(formVals[i])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fieldV.Index(i).SetInt(int64(val))
|
||||||
|
}
|
||||||
|
} else if fieldT.Type == sliceOfStrings {
|
||||||
|
formVals := form[tag]
|
||||||
|
fieldV.Set(reflect.MakeSlice(reflect.SliceOf(reflect.TypeOf("")), len(formVals), len(formVals)))
|
||||||
|
for i := 0; i < len(formVals); i++ {
|
||||||
|
fieldV.Index(i).SetString(formVals[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sliceOfInts = reflect.TypeOf([]int(nil))
|
||||||
|
var sliceOfStrings = reflect.TypeOf([]string(nil))
|
||||||
|
|
||||||
var unKind = map[reflect.Kind]bool{
|
var unKind = map[reflect.Kind]bool{
|
||||||
reflect.Uintptr: true,
|
reflect.Uintptr: true,
|
||||||
reflect.Complex64: true,
|
reflect.Complex64: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user