yamlpatch

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT, BSD-3-Clause Imports: 7 Imported by: 0

README

yamlpatch

This is a fork of https://github.com/evanphx/json-patch/tree/v5.9.0. This fork uses Gaby as the YAML parser and manipulation lib.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTestFailed          = errors.New("test failed")
	ErrMissing             = errors.New("missing value")
	ErrMissingKey          = errors.New("missing key")
	ErrUnknownType         = errors.New("unknown object type")
	ErrInvalid             = errors.New("invalid state detected")
	ErrInvalidIndex        = errors.New("invalid index referenced")
	ErrInvalidPatchFormat  = errors.New("invalid patch format")
	ErrAccumulatedCopySize = errors.New("accumulated copy size limit exceeded")
)
View Source
var AccumulatedCopySizeLimit int64 = 0

AccumulatedCopySizeLimit limits the total size increase in bytes caused by "copy" operations in a patch. If 0, there's no limit.

View Source
var SupportNegativeIndices = true

SupportNegativeIndices decides whether to support non-standard practice of allowing negative indices to mean indices starting at the end of an array. Default to true (mirroring the behavior in the provided jsonpatch example).

Functions

func Equal

func Equal(a, b []byte) bool

Equal indicates if 2 YAML documents have the same structural equality by parsing them into *gaby.YamlDoc and comparing their .Data() with reflect.DeepEqual.

Types

type Operation

type Operation map[string]interface{}

Operation is a single YAML Patch step, such as an "add" operation.

func (Operation) From

func (o Operation) From() (string, error)

func (Operation) Kind

func (o Operation) Kind() string

func (Operation) Path

func (o Operation) Path() (string, error)

func (Operation) ValueInterface

func (o Operation) ValueInterface() (interface{}, error)

ValueInterface decodes the "value" field from the Operation back into a Go interface{}, similar to the jsonpatch ValueInterface method.

type Patch

type Patch []Operation

Patch is an ordered collection of Operations.

func DecodePatch

func DecodePatch(y []byte) (Patch, error)

DecodePatch decodes a YAML patch document into a Patch. The patch document itself is expected to be a sequence of operations.

Example of a YAML patch document:

```yaml

  • op: add path: /items/- value: name: "New item"

  • op: remove path: /items/1

```

func (Patch) Apply

func (p Patch) Apply(doc []byte) ([]byte, error)

Apply applies a yamlpatch Patch to a YAML document. Returns the new document.

func (Patch) ApplyIndent

func (p Patch) ApplyIndent(doc []byte, indent int) ([]byte, error)

ApplyIndent is like Apply but returns an indented YAML string using the provided indentation.

Jump to

Keyboard shortcuts

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