patch

package
v0.99.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package patch applies RFC 6902 JSON Patch operations to a YAML release tree.

The patch itself is applied by a standard JSON Patch library, so serialization to JSON is required — which drops YAML custom tags (e.g. !lock), comments and key order. Those are restored from the original tree afterwards via yml.CopyMetadata. It also exposes a few node-level setters used for built-in transforms that must run before the JSON round-trip.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(doc *yaml.Node, ops []Op) (*yaml.Node, error)

Apply applies the ops to doc (a document node) and returns the resulting document. The patch is applied via a JSON Patch library; custom tags, comments and key order are then restored from doc, and styles are cleared so the result serializes as clean block YAML. When there are no ops, doc is returned unchanged.

func Scalar

func Scalar(value string) *yaml.Node

Scalar builds a plain string scalar node.

func SetPath

func SetPath(root *yaml.Node, tokens []string, val *yaml.Node) error

SetPath sets a mapping value at the given path (tokens), adding or replacing as needed. Every intermediate node must already exist and be a mapping. Used for built-in transforms.

func SetPathCreating

func SetPathCreating(root *yaml.Node, tokens []string, val *yaml.Node) error

SetPathCreating is like SetPath but creates any missing intermediate mapping nodes (merging into existing ones rather than clobbering). Used for built-ins that may target absent parents (e.g. metadata.labels).

Types

type Op

type Op struct {
	Op    string `json:"op"`
	Path  string `json:"path"`
	From  string `json:"from,omitempty"`
	Value any    `json:"value,omitempty"`
}

Op is a single RFC 6902 operation. Value is an arbitrary JSON value (set for add/replace); From is only set for move/copy.

func ParseOp

func ParseOp(data []byte) (Op, error)

ParseOp decodes a single RFC 6902 op from YAML or JSON.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL