traverser

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2019 License: MIT Imports: 3 Imported by: 5

README

traverser

Work with config data unmarshalled in to maps without knowing the shape of the data.

Used by:

  • envelope to do recursive decryption and arbitrary key getting / setting.
  • kpatch to apply expression results to Kubernetes manifests.

Tested with data from common yaml, json and toml parsers.

Documentation

Overview

Package traverser implements traversal of unknown structures with optional callbacks

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetKey

func GetKey(data interface{}, target []string) (interface{}, error)

GetKey will return the value at the target key

func SetKey

func SetKey(data interface{}, target []string, value interface{}) error

SetKey will set the value of the target key

Types

type Op

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

Op represents an operation to perform on a value passed to the Node callback. It is used to skip, mutate and handle error conditions.

func ErrorNoop

func ErrorNoop(err error) (Op, error)

ErrorNoop is a helper function that will return an Op that doesn't do anything but return an error

func ErrorSet

func ErrorSet(err error, v reflect.Value) (Op, error)

ErrorSet is a helper function that will return an Op that sets the key currently being traversed to the given value and returns an error

func ErrorUnset

func ErrorUnset(err error) (Op, error)

ErrorUnset is a helper function that will return an Op that unsets the key currently being traversed and returns an error

func Noop

func Noop() (Op, error)

Noop is a helper function that will return an Op that doesn't do anything

func Set

func Set(v reflect.Value) (Op, error)

Set is a helper function that will return an Op to set the key currently being traversed to the given value

func Skip

func Skip() (Op, error)

Skip is a helper function that will return an Op that will skip processing of the current node

func Unset

func Unset() (Op, error)

Unset is a helper function that will return an Op that unsets the key currently being traversed

type Traverser

type Traverser struct {
	Map    func(keys []string, key string, data reflect.Value)
	Node   func(keys []string, data reflect.Value) (Op, error)
	Accept func(keys []string, data reflect.Value) (Op, error)
}

Traverser is the main type and contains the Map & Node callbacks to be used. Map will be called each time a Map type is encountered Node will be called for each traversable element Accept will be called each time a traversal is made

func (*Traverser) Traverse

func (gt *Traverser) Traverse(data reflect.Value) error

Traverse is the recursive entrypoint for traversal of the given reflect.Value.

Jump to

Keyboard shortcuts

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