forked from giantswarm/azure-admission-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch.go
38 lines (35 loc) · 1.18 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
package mutator
// PatchOperation specifies one JSONPatch operation.
// See [RFC6902](https://tools.ietf.org/html/rfc6902) for details.
type PatchOperation struct {
Operation string `json:"op"`
Path string `json:"path"`
Value interface{} `json:"value"`
}
// PatchReplace creates a patch operation of type "replace".
func PatchReplace(path string, value interface{}) PatchOperation {
return PatchOperation{
Operation: "replace",
Path: path,
Value: value,
}
}
// PatchAdd creates a patch operation of type "add".
//
// The "add" operation performs one of the following functions,
// depending upon what the target location references:
//
// - If the target location specifies an array index, a new value is
// inserted into the array at the specified index.
// - If the target location specifies an object member that does not
// already exist, a new member is added to the object.
// - If the target location specifies an object member that does exist,
// that member's value is replaced.
//
func PatchAdd(path string, value interface{}) *PatchOperation {
return &PatchOperation{
Operation: "add",
Path: path,
Value: value,
}
}