jp

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NilPathErr = errors.New("path is nil")
	NilFromErr = errors.New("from is nil")
)
View Source
var (
	DefaultJsonPatchOpt = &jsonpatch.ApplyOptions{
		SupportNegativeIndices:   jsonpatch.SupportNegativeIndices,
		AccumulatedCopySizeLimit: jsonpatch.AccumulatedCopySizeLimit,
		AllowMissingPathOnRemove: true,
		EnsurePathExistsOnAdd:    true,
	}

	EmptyPathOrValueErr = errors.New("paths and values must not be empty")
	PathValueLengthErr  = errors.New("paths and values must have the same length")
)

Functions

func ApplyJsonPatch

func ApplyJsonPatch[T any](b []byte, encodeFn func(T) ([]byte, error)) (func(T) ([]byte, error), error)

func ApplyJsonPatchFromPatch

func ApplyJsonPatchFromPatch[T any](encodeFn func(T) ([]byte, error), patches ...Patch) (func(T) ([]byte, error), error)

func EqualJsonPatchFromPatch

func EqualJsonPatchFromPatch[T any](encodeFn func(T) ([]byte, error), paths []string, values []interface{}) (func(T) error, error)

Types

type Patch

type Patch struct {
	Op    PatchOp     `json:"op,omitempty" yaml:"op,omitempty"`
	Path  *string     `json:"path,omitempty" yaml:"path,omitempty"`
	From  *string     `json:"from,omitempty" yaml:"from,omitempty"`
	Value interface{} `json:"value,omitempty" yaml:"value,omitempty"`
}

func (*Patch) String

func (p *Patch) String() string

func (*Patch) UnmarshalJSON

func (p *Patch) UnmarshalJSON(b []byte) error

type PatchOp

type PatchOp string
const (
	TestPatchOp    PatchOp = "test"
	RemovePatchOp  PatchOp = "remove"
	AddPatchOp     PatchOp = "add"
	ReplacePatchOp PatchOp = "replace"
	MovePatchOp    PatchOp = "move"
	CopyPatchOp    PatchOp = "copy"
)

type Patches

type Patches []Patch

func SelectInputByPaths

func SelectInputByPaths(metadata string, doc []byte, paths []string, jsonPatchOpt *jsonpatch.ApplyOptions) (Patches, error)

func (Patches) String

func (ps Patches) String() string

Jump to

Keyboard shortcuts

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