lensed

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: BSD-2-Clause Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Default is the default map of lenses.
	Default = LensMap{
		"":            YAMLLens{},
		"yaml":        YAMLLens{},
		"yamls":       MultiYAMLLens{},
		"toml":        TOMLLens{},
		"base64":      Base64Lens{},
		"line":        LineLens{},
		"regexp":      RegexpLens{},
		"ociImageRef": OCIImageRef{},
		"oci":         OCIImageRef{},
		"jsonnet":     Jsonnet{},
	}
)

Functions

func Apply

func Apply(src []byte, m []Mapping) ([]byte, error)

Apply invokes Apply on the Default lens map.

func Get

func Get(src []byte, ptrs []string) ([][]byte, error)

Get invokes Get on the Default lens map.

Types

type AppliedLensMap

type AppliedLensMap struct {
	// contains filtered or unexported fields
}

An AppliedLensMap is a Replacer that applied mappings to its inputs.

func (AppliedLensMap) Transform

func (a AppliedLensMap) Transform(src []byte) ([]byte, error)

Transform implements the Replacer interface.

type Base64Lens

type Base64Lens struct{}

Base64Lens implements the "base64" lens.

func (Base64Lens) Apply

func (Base64Lens) Apply(src []byte, vals []Setter) ([]byte, error)

Apply implements the Lens interface.

type Jsonnet

type Jsonnet struct{}

Jsonnet implements the "jsonnet" lens.

The jsonnet lens implementation is still in its early stages, it only supports: 1. double quoted string scalars 2. single level ~{"foo":"bar", "baz":"quz"} matchers

func (Jsonnet) Apply

func (Jsonnet) Apply(src []byte, vals []Setter) ([]byte, error)

Apply implements the Lens interface.

type Lens

type Lens interface {
	Apply(src []byte, m []Setter) ([]byte, error)
}

A Lens knows how to perform in-place edits of parts of a text. The parts are addressed using JSONPointer pointers. The new value is provided via a transformer which allows, among other things, to nest lenses.

type LensMap

type LensMap map[string]Lens

A LensMap is a collection of named lenses.

func (LensMap) Apply

func (lm LensMap) Apply(src []byte, ms []Mapping) ([]byte, error)

Apply applies a slice of mappings on a source byte slice, resolving lens names from the lens map.

func (LensMap) ApplySetters

func (lm LensMap) ApplySetters(src []byte, setters []Setter) ([]byte, error)

ApplySetters applies a slice of setters on a source byte slice, resolving lens names from the lens map.

func (LensMap) Get

func (lm LensMap) Get(src []byte, ptrs []string) ([][]byte, error)

Get returns a slice of byte slices, each one containing the value of a field addressed by a pointer.

func (LensMap) Replacer

func (lm LensMap) Replacer(ms []Mapping) AppliedLensMap

Replacer returns a Replacer implementation that applies mappings to its input.

type LineLens

type LineLens struct{}

LineLens implements the "line" lens. The line lens selects a line matching a regexp. Like awk's or sed's "/regexp/" construct.

func (LineLens) Apply

func (LineLens) Apply(src []byte, vals []Setter) ([]byte, error)

Apply implements the Lens interface.

type Mapping

type Mapping struct {
	Pointer     string
	Replacement string
}

A Mapping is a request to replace the value pointed by pointer with a replacement string.

type MultiYAMLLens

type MultiYAMLLens struct{}

MultiYAMLLens implements the "yamls" lens.

func (MultiYAMLLens) Apply

func (MultiYAMLLens) Apply(src []byte, vals []Setter) ([]byte, error)

Apply implements the Lens interface.

type OCIImageRef

type OCIImageRef struct{}

OCIImageRef implements the "oci" lens. The current implementation is very rough and only supports image name and tag. The image name cannot contain a port number.

func (OCIImageRef) Apply

func (OCIImageRef) Apply(src []byte, vals []Setter) ([]byte, error)

Apply implements the Lens interface.

type RegexpLens

type RegexpLens struct{}

RegexpLens implements the "regexp" lens. The regexp find a selection matching a regexp and exposes capturing groups as child nodes. Child nodes can be referenced by number or by name if the subexpressions is named with the naming syntax "(?P<name>re)").

func (RegexpLens) Apply

func (RegexpLens) Apply(src []byte, vals []Setter) ([]byte, error)

Apply implements the Lens interface.

type Replacer

type Replacer interface {
	Transform(src []byte) ([]byte, error)
}

A Replacer transforms a byte slice into another byte slice.

type ReplacerTransformer

type ReplacerTransformer struct {
	// contains filtered or unexported fields
}

A ReplacerTransformer is a transform.Transformer that applies a Replacer.

func NewTransformer

func NewTransformer(r Replacer) ReplacerTransformer

NewTransformer returns a transform.Transform implementation for a given replacer.

func (*ReplacerTransformer) Reset

func (t *ReplacerTransformer) Reset()

Reset implements the golang.org/x/text/transform.Transformer interface.

func (*ReplacerTransformer) Transform

func (t *ReplacerTransformer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)

Transform implements the golang.org/x/text/transform.Transformer interface.

type Setter

type Setter struct {
	Pointer string
	Value   Replacer
}

A Setter is like a mapping but uses a Replacer to update the existing value pointed by the pointer.

type TOMLLens

type TOMLLens struct{}

TOMLLens implements the "toml" lens.

func (TOMLLens) Apply

func (TOMLLens) Apply(src []byte, vals []Setter) ([]byte, error)

Apply implements the Lens interface.

type YAMLLens

type YAMLLens struct{}

YAMLLens implements the "yaml" lens.

func (YAMLLens) Apply

func (YAMLLens) Apply(src []byte, vals []Setter) ([]byte, error)

Apply implements the Lens interface.

Jump to

Keyboard shortcuts

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