github.com/Racer159/jackal@v0.32.7-0.20240401174413-0bd2339e4f2e/src/internal/agent/operations/patch.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: 2021-Present The Jackal Authors 3 4 // Package operations provides json patch operations. 5 package operations 6 7 const ( 8 addOperation = "add" 9 removeOperation = "remove" 10 replaceOperation = "replace" 11 copyOperation = "copy" 12 moveOperation = "move" 13 ) 14 15 // PatchOperation is an operation of a JSON patch https://tools.ietf.org/html/rfc6902. 16 type PatchOperation struct { 17 Op string `json:"op"` 18 Path string `json:"path"` 19 From string `json:"from,omitempty"` 20 Value interface{} `json:"value,omitempty"` 21 } 22 23 // AddPatchOperation returns an add JSON patch operation. 24 func AddPatchOperation(path string, value interface{}) PatchOperation { 25 return PatchOperation{ 26 Op: addOperation, 27 Path: path, 28 Value: value, 29 } 30 } 31 32 // RemovePatchOperation returns a remove JSON patch operation. 33 func RemovePatchOperation(path string) PatchOperation { 34 return PatchOperation{ 35 Op: removeOperation, 36 Path: path, 37 } 38 } 39 40 // ReplacePatchOperation returns a replace JSON patch operation. 41 func ReplacePatchOperation(path string, value interface{}) PatchOperation { 42 return PatchOperation{ 43 Op: replaceOperation, 44 Path: path, 45 Value: value, 46 } 47 } 48 49 // CopyPatchOperation returns a copy JSON patch operation. 50 func CopyPatchOperation(from, path string) PatchOperation { 51 return PatchOperation{ 52 Op: copyOperation, 53 Path: path, 54 From: from, 55 } 56 } 57 58 // MovePatchOperation returns a move JSON patch operation. 59 func MovePatchOperation(from, path string) PatchOperation { 60 return PatchOperation{ 61 Op: moveOperation, 62 Path: path, 63 From: from, 64 } 65 }