-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
69 lines (64 loc) · 971 Bytes
/
example_test.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
package mjsonpatch
import "fmt"
var T = []byte(`{
"interests": [
"basketball"
],
"A": {
"a3": [
{}
]
}
}`)
var T2 = []byte(`{
"name": "string",
"interests": [
"basketball",
"pingpong"
],
"A": {
"a1": "string",
"a2": "int",
"a3": [
{
"b1": 1,
"b2": "2"
},
{
"b1": 3,
"b2": "4"
}
]
},
"B": "string"
}`)
var patch = []byte(`[
{
"op": "add",
"path": "/interests/0",
"value": "football"
},
{
"op": "add",
"path": "/B",
"value": "xiongxiaoxiao"
},
{
"op": "replace",
"path": "/A/a1",
"value": "a1-replace"
},
{
"op": "remove",
"path": "/A/a3/1",
"value": ""
}
]`)
func ExampleMongoOP() {
tpl := NewTemplate(T)
ps, _ := Patchs(patch)
m, _ := MongoOP(tpl, ps)
fmt.Printf("%+v", m)
// Output:
// map[$pull:map[A.a3:<nil>] $push:map[interests:map[$each:[football] $position:0]] $set:map[A.a1:a1-replace B:xiongxiaoxiao] $unset:map[A.a3.1:]]
}