- fixed TestDictKeysMan bug
- order api added.
This commit is contained in:
@@ -6,6 +6,17 @@ import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func GetConcretValue(value reflect.Value) reflect.Value {
|
||||
for {
|
||||
if value.Kind() == reflect.Interface || value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func DictKeysMan(data interface{}, keysToRemove []string, keysToKeep []string) interface{} {
|
||||
if data == nil || (keysToKeep == nil && keysToRemove == nil) {
|
||||
return data
|
||||
@@ -37,10 +48,7 @@ func DictKeysMan(data interface{}, keysToRemove []string, keysToKeep []string) i
|
||||
retVal := make([]interface{}, valueOfData.Len())
|
||||
|
||||
for index := 0; index < valueOfData.Len(); index++ {
|
||||
realV := valueOfData.Index(index)
|
||||
if realV.Kind() == reflect.Interface || realV.Kind() == reflect.Ptr {
|
||||
realV = realV.Elem()
|
||||
}
|
||||
realV := GetConcretValue(valueOfData.Index(index))
|
||||
if keysToRemoveMap != nil || keysToKeepMap != nil {
|
||||
mapV := make(map[string]interface{})
|
||||
for _, key := range realV.MapKeys() {
|
||||
@@ -56,7 +64,7 @@ func DictKeysMan(data interface{}, keysToRemove []string, keysToKeep []string) i
|
||||
}
|
||||
}
|
||||
if wantThisField {
|
||||
mapV[fieldName] = realV.MapIndex(key)
|
||||
mapV[fieldName] = GetConcretValue(realV.MapIndex(key)).Interface()
|
||||
}
|
||||
}
|
||||
retVal[index] = mapV
|
||||
@@ -76,3 +84,10 @@ func UnmarshalUseNumber(data []byte, result interface{}) error {
|
||||
d.UseNumber()
|
||||
return d.Decode(result)
|
||||
}
|
||||
|
||||
func Bool2String(value bool) string {
|
||||
if value {
|
||||
return "true"
|
||||
}
|
||||
return "false"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user