-
Notifications
You must be signed in to change notification settings - Fork 7
/
predicate.go
52 lines (40 loc) · 1.62 KB
/
predicate.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
package jsonpatch
// Predicate filters patches
type Predicate interface {
// Add returns true if the object should not be added in the patch
Add(pointer JSONPointer, modified interface{}) bool
// Remove returns true if the object should not be deleted in the patch
Remove(pointer JSONPointer, current interface{}) bool
// Replace returns true if the objects should not be updated in the patch - this will stop the recursive processing of those objects
Replace(pointer JSONPointer, modified, current interface{}) bool
}
// Funcs is a function that implements Predicate
type Funcs struct {
// Add returns true if the object should not be added in the patch
AddFunc func(pointer JSONPointer, modified interface{}) bool
// Remove returns true if the object should not be deleted in the patch
RemoveFunc func(pointer JSONPointer, current interface{}) bool
// Replace returns true if the objects should not be updated in the patch - this will stop the recursive processing of those objects
ReplaceFunc func(pointer JSONPointer, modified, current interface{}) bool
}
// Add implements Predicate
func (p Funcs) Add(pointer JSONPointer, modified interface{}) bool {
if p.AddFunc != nil {
return p.AddFunc(pointer, modified)
}
return true
}
// Remove implements Predicate
func (p Funcs) Remove(pointer JSONPointer, current interface{}) bool {
if p.RemoveFunc != nil {
return p.RemoveFunc(pointer, current)
}
return true
}
// Replace implements Predicate
func (p Funcs) Replace(pointer JSONPointer, modified, current interface{}) bool {
if p.ReplaceFunc != nil {
return p.ReplaceFunc(pointer, modified, current)
}
return true
}