forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.process.go
71 lines (62 loc) · 1.95 KB
/
map.process.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package helper
import (
"fmt"
"github.com/yaoapp/gou/process"
)
// ProcessMapValues xiang.helper.MapValues 返回映射表的数值
func ProcessMapValues(process *process.Process) interface{} {
process.ValidateArgNums(1)
record := process.ArgsMap(0)
return MapValues(record)
}
// ProcessMapKeys xiang.helper.MapKeys 返回映射表的键
func ProcessMapKeys(process *process.Process) interface{} {
process.ValidateArgNums(1)
record := process.ArgsMap(0)
return MapKeys(record)
}
// ProcessMapGet xiang.helper.MapGet 返回映射表给定键的值
func ProcessMapGet(process *process.Process) interface{} {
process.ValidateArgNums(2)
record := process.ArgsMap(0)
key := process.ArgsString(1)
return MapGet(record, key)
}
// ProcessMapSet xiang.helper.MapSet 设定键值,返回映射表给定键的值
func ProcessMapSet(process *process.Process) interface{} {
process.ValidateArgNums(3)
record := process.ArgsMap(0)
key := process.ArgsString(1)
value := process.Args[2]
return MapSet(record, key, value)
}
// ProcessMapDel xiang.helper.MapDel 删除给定键, 返回映射表
func ProcessMapDel(process *process.Process) interface{} {
process.ValidateArgNums(2)
record := process.ArgsMap(0)
key := process.ArgsString(1)
return MapDel(record, key)
}
// ProcessMapMultiDel xiang.helper.MapMultiDel 删除一组给定键, 返回映射表
func ProcessMapMultiDel(process *process.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...)
}
// ProcessMapToArray xiang.helper.MapToArray 映射转换为 KeyValue 数组
func ProcessMapToArray(process *process.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
}