- 将FlatMap,Struct2FlatMap从jxutils移到utils中
This commit is contained in:
@@ -48,38 +48,13 @@ func DeSerializeData(strValue string, dataPtr interface{}) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func FlatMap(in map[string]interface{}) map[string]interface{} {
|
||||
keys := []string{}
|
||||
maps := []map[string]interface{}{}
|
||||
for k, v := range in {
|
||||
if vMap, ok := v.(map[string]interface{}); ok {
|
||||
vMap = FlatMap(vMap)
|
||||
maps = append(maps, vMap)
|
||||
keys = append(keys, k)
|
||||
}
|
||||
}
|
||||
if len(maps) > 0 {
|
||||
retVal := utils.MergeMaps(in, maps...)
|
||||
for _, v := range keys {
|
||||
delete(retVal, v)
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
return in
|
||||
}
|
||||
|
||||
func Struct2FlatMap(obj interface{}) map[string]interface{} {
|
||||
m := utils.Struct2MapByJson(obj)
|
||||
return FlatMap(m)
|
||||
}
|
||||
|
||||
// todo 这里看是否需要将key值转换成标准格式(即字母大写),因为beego orm不区分,不转换也可以
|
||||
func FilterMapByStructObject(mapData map[string]interface{}, obj interface{}, excludedFields []string, isCheckValue bool) (valid map[string]interface{}, invalid map[string]interface{}) {
|
||||
excludedMap := make(map[string]int)
|
||||
for _, v := range excludedFields {
|
||||
excludedMap[v] = 1
|
||||
}
|
||||
m := Struct2FlatMap(obj)
|
||||
m := utils.Struct2FlatMap(obj)
|
||||
valid = make(map[string]interface{})
|
||||
invalid = make(map[string]interface{})
|
||||
for k, v := range mapData {
|
||||
|
||||
Reference in New Issue
Block a user