yamlpatch

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package yamlpatch is a library for applying RFC6902 JSON patches to yaml documents. It leverages go-yaml v3's Node type to preserve comments, ordering, and most formatting.

Index

Constants

View Source
const (
	OperationAdd     = "add"
	OperationReplace = "replace"
	OperationRemove  = "remove"
	OperationMove    = "move"
	OperationCopy    = "copy"
	OperationTest    = "test"
)

Variables

This section is empty.

Functions

func Apply

func Apply(originalBytes []byte, patch Patch) ([]byte, error)

Apply the patch to a yaml document provided in originalBytes and return the updated content. A best effort is made to minimize changes outside the patched paths but some whitespace changes are unavoidable.

Types

type Operation

type Operation struct {
	Type  string      `json:"op" yaml:"op"`
	Path  Path        `json:"path" yaml:"path"`
	From  Path        `json:"from,omitempty" yaml:"from,omitempty"`
	Value interface{} `json:"value,omitempty" yaml:"value,omitempty"`
}

Operation represents a RFC6902 JSON Patch operation.

func (Operation) String

func (op Operation) String() string

type Patch

type Patch []Operation

type Path

type Path []string

Path represents a decoded JSON patch targeting a location within a document. Use ParsePath or UnmarshalText to construct a Path.

func MustParsePath

func MustParsePath(str string) Path

MustParsePath is like ParsePath but panics in case of invalid input.

func ParsePath

func ParsePath(str string) (Path, error)

func (Path) Key

func (p Path) Key() string

func (Path) MarshalText

func (p Path) MarshalText() ([]byte, error)

func (Path) String

func (p Path) String() string

func (*Path) UnmarshalText

func (p *Path) UnmarshalText(text []byte) error

Jump to

Keyboard shortcuts

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