+ Heper: MapMultiDel
This commit is contained in:
parent
747b395e3d
commit
93071b583f
4 changed files with 38 additions and 3 deletions
|
|
@ -37,3 +37,11 @@ func MapDel(record map[string]interface{}, key string) map[string]interface{} {
|
|||
delete(record, key)
|
||||
return record
|
||||
}
|
||||
|
||||
// MapMultiDel xiang.helper.MapMultiDel 删除数值并返回新映射表
|
||||
func MapMultiDel(record map[string]interface{}, keys ...string) map[string]interface{} {
|
||||
for _, key := range keys {
|
||||
delete(record, key)
|
||||
}
|
||||
return record
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
package helper
|
||||
|
||||
import "github.com/yaoapp/gou"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
)
|
||||
|
||||
// ProcessMapValues xiang.helper.MapValues 返回映射表的数值
|
||||
func ProcessMapValues(process *gou.Process) interface{} {
|
||||
|
|
@ -24,7 +28,7 @@ func ProcessMapGet(process *gou.Process) interface{} {
|
|||
return MapGet(record, key)
|
||||
}
|
||||
|
||||
// ProcessMapSet xiang.helper.MapSet 返回映射表给定键的值
|
||||
// ProcessMapSet xiang.helper.MapSet 设定键值,返回映射表给定键的值
|
||||
func ProcessMapSet(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(3)
|
||||
record := process.ArgsMap(0)
|
||||
|
|
@ -33,10 +37,21 @@ func ProcessMapSet(process *gou.Process) interface{} {
|
|||
return MapSet(record, key, value)
|
||||
}
|
||||
|
||||
// ProcessMapDel xiang.helper.MapDel 返回映射表给定键的值
|
||||
// ProcessMapDel xiang.helper.MapDel 删除给定键, 返回映射表
|
||||
func ProcessMapDel(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
record := process.ArgsMap(0)
|
||||
key := process.ArgsString(1)
|
||||
return MapDel(record, key)
|
||||
}
|
||||
|
||||
// ProcessMapMultiDel xiang.helper.MapMultiDel 删除一组给定键, 返回映射表
|
||||
func ProcessMapMultiDel(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
record := process.ArgsMap(0)
|
||||
keys := []string{}
|
||||
for _, key := range process.Args {
|
||||
keys = append(keys, fmt.Sprintf("%v", key))
|
||||
}
|
||||
return MapMultiDel(record, keys...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,3 +49,14 @@ func TestProcessMapValues(t *testing.T) {
|
|||
assert.Contains(t, values, "Value1")
|
||||
assert.Contains(t, values, "Value2")
|
||||
}
|
||||
|
||||
func TestProcessMapMultiDel(t *testing.T) {
|
||||
args := []interface{}{
|
||||
map[string]interface{}{"foo": "Value1", "bar": "Value2"},
|
||||
"foo",
|
||||
"bar",
|
||||
}
|
||||
new := gou.NewProcess("xiang.helper.MapMultiDel", args...).Run().(map[string]interface{})
|
||||
assert.Nil(t, new["foo"])
|
||||
assert.Nil(t, new["bar"])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ func init() {
|
|||
gou.RegisterProcessHandler("xiang.helper.MapGet", ProcessMapGet)
|
||||
gou.RegisterProcessHandler("xiang.helper.MapSet", ProcessMapSet)
|
||||
gou.RegisterProcessHandler("xiang.helper.MapDel", ProcessMapDel)
|
||||
gou.RegisterProcessHandler("xiang.helper.MapMultiDel", ProcessMapMultiDel)
|
||||
|
||||
gou.RegisterProcessHandler("xiang.helper.StrConcat", ProcessStrConcat)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue