+ MapToArray Helper
This commit is contained in:
parent
43849e8456
commit
ee50523980
3 changed files with 28 additions and 0 deletions
|
|
@ -55,3 +55,17 @@ func ProcessMapMultiDel(process *gou.Process) interface{} {
|
|||
}
|
||||
return MapMultiDel(record, keys...)
|
||||
}
|
||||
|
||||
// ProcessMapToArray xiang.helper.MapToArray 映射转换为 KeyValue 数组
|
||||
func ProcessMapToArray(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
m := process.ArgsMap(0)
|
||||
res := []map[string]interface{}{}
|
||||
for key, value := range m {
|
||||
res = append(res, map[string]interface{}{
|
||||
"key": key,
|
||||
"value": value,
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,3 +60,16 @@ func TestProcessMapMultiDel(t *testing.T) {
|
|||
assert.Nil(t, new["foo"])
|
||||
assert.Nil(t, new["bar"])
|
||||
}
|
||||
|
||||
func TestProcessMapToArray(t *testing.T) {
|
||||
|
||||
arr := gou.NewProcess("xiang.helper.MapToArray", map[string]interface{}{
|
||||
"foo": "Value1",
|
||||
"bar": "Value2",
|
||||
}).Run().([]map[string]interface{})
|
||||
|
||||
assert.Equal(t, arr[0]["key"], "foo")
|
||||
assert.Equal(t, arr[0]["value"], "Value1")
|
||||
assert.Equal(t, arr[1]["key"], "bar")
|
||||
assert.Equal(t, arr[1]["value"], "Value2")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ func init() {
|
|||
|
||||
gou.RegisterProcessHandler("xiang.helper.MapKeys", ProcessMapKeys)
|
||||
gou.RegisterProcessHandler("xiang.helper.MapValues", ProcessMapValues)
|
||||
gou.RegisterProcessHandler("xiang.helper.MapToArray", ProcessMapToArray)
|
||||
gou.RegisterProcessHandler("xiang.helper.MapGet", ProcessMapGet)
|
||||
gou.RegisterProcessHandler("xiang.helper.MapSet", ProcessMapSet)
|
||||
gou.RegisterProcessHandler("xiang.helper.MapDel", ProcessMapDel)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue