mirror of
https://github.com/beego/bee.git
synced 2024-11-21 23:50:54 +00:00
refactor reflection template for models
This commit is contained in:
parent
6a7428b3aa
commit
f879d728c8
14
g_models.go
14
g_models.go
@ -684,19 +684,11 @@ func GetAll{{modelName}}(query map[string]string, fields []string, sortby []stri
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// trim unused fields
|
// trim unused fields
|
||||||
fieldMap := make(map[string]interface{})
|
|
||||||
for _, v := range fields {
|
|
||||||
fieldMap[v] = true
|
|
||||||
}
|
|
||||||
for _, v := range l {
|
for _, v := range l {
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
s := reflect.Indirect(reflect.ValueOf(v))
|
val := reflect.ValueOf(v)
|
||||||
typeOfS := s.Type()
|
for _, fname := range fields {
|
||||||
for i := 0; i < s.NumField(); i++ {
|
m[fname] = val.FieldByName(fname).Interface()
|
||||||
f := s.Field(i)
|
|
||||||
if _, ok := fieldMap[typeOfS.Field(i).Name]; ok {
|
|
||||||
m[typeOfS.Field(i).Name] = f.Interface()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ml = append(ml, m)
|
ml = append(ml, m)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user