Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyFilters(input string, filters ...FilterFunc) string
- func DeleteFromMap(parentMap interface{}, key interface{}) error
- func DeleteFromSlicePtr(parentSlice interface{}, index int) error
- func DiffYAML(a, b string) (string, error)
- func FormatterFilter(input string) string
- func InsertIntoMap(parentMap interface{}, key interface{}, value interface{}) error
- func IsKVPathElement(pe string) bool
- func IsMap(value interface{}) bool
- func IsNPathElement(pe string) bool
- func IsNilOrInvalidValue(v reflect.Value) bool
- func IsSlice(value interface{}) bool
- func IsSliceInterfacePtr(v interface{}) bool
- func IsVPathElement(pe string) bool
- func IsValidPathElement(pe string) bool
- func IsValueMap(v reflect.Value) bool
- func IsValueNil(value interface{}) bool
- func IsValueNilOrDefault(value interface{}) bool
- func IsValuePtr(v reflect.Value) bool
- func IsValueScalar(v reflect.Value) bool
- func IsValueSlice(v reflect.Value) bool
- func IsValueStruct(v reflect.Value) bool
- func IsYAMLEmpty(y string) bool
- func JoinYAML(segs []string) string
- func LicenseFilter(input string) string
- func OverlayYAML(base, overlay string) (string, error)
- func PathKV(pe string) (k, v string, err error)
- func PathN(pe string) (int, error)
- func PathV(pe string) (string, error)
- func RemoveBrackets(pe string) (string, bool)
- func SpaceFilter(input string) string
- func SpaceLineFilter(input string) string
- func SplitYAML(y string) ([]string, error)
- func TestYAMLEqual(golden, result string) (bool, string, error)
- type FilterFunc
- type Path
Constants ¶
const ( PathSeparator = "." EscapedPathSeparator = "\\" + PathSeparator InsertIndex = -1 )
Variables ¶
var ValidKeyRegex = regexp.MustCompile("^[a-zA-Z0-9_-]*$")
ValidKeyRegex is a regex for a valid path key element.
Functions ¶
func ApplyFilters ¶
func ApplyFilters(input string, filters ...FilterFunc) string
func DeleteFromMap ¶
func DeleteFromMap(parentMap interface{}, key interface{}) error
DeleteFromMap deletes an entry with the given key parent, which must be a map.
func DeleteFromSlicePtr ¶
DeleteFromSlicePtr deletes an entry at index from the parent, which must be a slice ptr.
func DiffYAML ¶
DiffYAML accepts two single yaml(not with "---" yaml separator). Returns a string containing a line-by-line unified diff of the linewise changes required to make A into B. Each line is prefixed with '+', '-', or ' ' to indicate if it should be added, removed, or is correct respectively.
eg: a: key: val
key1: val1
b: key: val
key1: val2
return: key: val
-key1: val1 +key1: val2
func FormatterFilter ¶
FormatterFilter uses github.com/google/yamlfmt to format yaml file
func InsertIntoMap ¶
func InsertIntoMap(parentMap interface{}, key interface{}, value interface{}) error
InsertIntoMap inserts value with key into parent which must be a map, map ptr, or interface to map.
func IsKVPathElement ¶
IsKVPathElement report whether pe is a key/value path element.
func IsNPathElement ¶
IsNPathElement report whether pe is an index path element.
func IsNilOrInvalidValue ¶
IsNilOrInvalidValue reports whether v is nil or reflect.Zero.
func IsSliceInterfacePtr ¶
func IsSliceInterfacePtr(v interface{}) bool
IsSliceInterfacePtr reports whether v is a slice ptr type.
func IsVPathElement ¶
IsVPathElement report whether pe is a value path element.
func IsValidPathElement ¶
IsValidPathElement reports whether pe is a valid path element.
func IsValueNil ¶
func IsValueNil(value interface{}) bool
IsValueNil returns true if either value is nil, or has dynamic type {ptr, map, slice} with value nil.
func IsValueNilOrDefault ¶
func IsValueNilOrDefault(value interface{}) bool
IsValueNilOrDefault returns true if either IsValueNil(value) or the default value for the type.
func IsValueScalar ¶
IsValueScalar reports whether v is a scalar type.
func IsValueSlice ¶
IsValueSlice reports whether v is a slice type.
func IsValueStruct ¶
IsValueStruct reports whether v is a struct type.
func IsYAMLEmpty ¶
IsYAMLEmpty reports whether the YAML string y is logically empty.
func LicenseFilter ¶
LicenseFilter assumes that license is at the beginning. So we just remove all the leading comments until the first non-comment line appears.
func OverlayYAML ¶
OverlayYAML patches the overlay tree over the base tree and returns the result. All trees are expressed as YAML strings.
func PathKV ¶
PathKV returns the key and value string parts of the entire key/value path element. It returns an error if pe is not a key/value path element.
func PathN ¶
PathN returns the index part of the entire value path element. It returns an error if pe is not an index path element.
func PathV ¶
PathV returns the value string part of the entire value path element. It returns an error if pe is not a value path element.
func RemoveBrackets ¶
RemoveBrackets removes the [] around pe and returns the resulting string. It returns false if pe is not surrounded by [].
func SpaceFilter ¶
SpaceFilter removes all leading and trailing space.
func SpaceLineFilter ¶
SpaceLineFilter removes all space lines.
func TestYAMLEqual ¶
TestYAMLEqual judges whether golden and result yaml are the same and return the diff if they are different. If this function returns error, it means that golden file or result file could not be formatted. eg:
golden: line result: line return: true, "" golden: lineG result: lineR return: false, line 1 diff: --golden-- lineG --result-- lineR golden: line result: line lineAdd return: false, line 2 to 2: --result addition-- lineAdd
Types ¶
type FilterFunc ¶
FilterFunc is used to filter some contents of manifest.
type Path ¶
type Path []string
Path is a path in slice form.
func PathFromString ¶
PathFromString converts a string path of form a.b.c to a string slice representation.
func ToYAMLPath ¶
ToYAMLPath converts a path string to path such that the first letter of each path element is lower case.