-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch.go
61 lines (54 loc) · 1.43 KB
/
patch.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
package admissioncontroller
const (
addOperation = "add"
removeOperation = "remove"
replaceOperation = "replace"
copyOperation = "copy"
moveOperation = "move"
)
// PatchOperation is an operation of a JSON patch https://tools.ietf.org/html/rfc6902.
type PatchOperation struct {
Op string `json:"op"`
Path string `json:"path"`
From string `json:"from"`
Value interface{} `json:"value,omitempty"`
}
// AddPatchOperation returns an add JSON patch operation.
func AddPatchOperation(path string, value interface{}) PatchOperation {
return PatchOperation{
Op: addOperation,
Path: path,
Value: value,
}
}
// RemovePatchOperation returns a remove JSON patch operation.
func RemovePatchOperation(path string) PatchOperation {
return PatchOperation{
Op: removeOperation,
Path: path,
}
}
// ReplacePatchOperation returns a replace JSON patch operation.
func ReplacePatchOperation(path string, value interface{}) PatchOperation {
return PatchOperation{
Op: replaceOperation,
Path: path,
Value: value,
}
}
// CopyPatchOperation returns a copy JSON patch operation.
func CopyPatchOperation(from, path string) PatchOperation {
return PatchOperation{
Op: copyOperation,
Path: path,
From: from,
}
}
// MovePatchOperation returns a move JSON patch operation.
func MovePatchOperation(from, path string) PatchOperation {
return PatchOperation{
Op: moveOperation,
Path: path,
From: from,
}
}