refvar

package
v0.0.0-...-59ba1d5 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package refvar contains a kio.Filter implementation of the kustomize refvar transformer (find and replace $(FOO) style variables in strings).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoReplacements

func DoReplacements(input string, mapping MappingFunc) interface{}

DoReplacements replaces variable references in the input string using the mapping function.

Types

type Filter

type Filter struct {
	MappingFunc MappingFunc     `json:"mappingFunc,omitempty" yaml:"mappingFunc,omitempty"`
	FieldSpec   types.FieldSpec `json:"fieldSpec,omitempty" yaml:"fieldSpec,omitempty"`
}

Filter updates $(VAR) style variables with values. The fieldSpecs are the places to look for occurrences of $(VAR).

func (Filter) Filter

func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error)

type MappingFunc

type MappingFunc func(string) interface{}

MappingFunc maps a string to anything.

func MakePrimitiveReplacer

func MakePrimitiveReplacer(
	counts map[string]int, someMap map[string]interface{}) MappingFunc

MakePrimitiveReplacer returns a MappingFunc that uses a map to do replacements, and a histogram to count map hits.

Func behavior:

If the input key is NOT found in the map, the key is wrapped up as as a variable declaration string and returned, e.g. key FOO becomes $(FOO). This string is presumably put back where it was found, and might get replaced later.

If the key is found in the map, the value is returned if it is a primitive type (string, bool, number), and the hit is counted.

If it's not a primitive type (e.g. a map, struct, func, etc.) then this function doesn't know what to do with it and it returns the key wrapped up again as if it had not been replaced. This should probably be an error.

Jump to

Keyboard shortcuts

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