change

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equals

func Equals(from, to interface{}) bool

Equals checks if the from and to objects are equal using reflect.DeepEquals

func GetValue

func GetValue(source, v interface{}, path *Node) (err error)

GetValue attempts to extract a value from sources object graph using the supplied path, returning the found value by reference in v v must be the same type as the node pointed to by the supplied path

Types

type Node

type Node struct {
	Path      []NodeDetail
	HandlerFn func(from, to interface{}, path *Node) error
}

Node in the object graph which if present should result in the HandlerFn being invoked where HandlerFn takes a resource objects current and desired states, with the provider responsible for testing equality and subsequent handling of any required changes to the resource.

For example, say you have the following types:

type Car struct {
	Make string
	Age  int
	Fuel Fuel
}

type Fuel struct {
	Make     string
	Unleaded bool
}

You can create a change node with handler function for the Unleaded field in a Car object as follows.

handler := func(have, want interface{}, path *change.Node) error {
    fmt.Printf("Handle the change here")
}
node := NewNode().Field("Fuel").Field("Unleaded").Handler(handler)

The handler function can be a closure to include additional objects such as API clients, look at the digitalocean package for an example of this.

func NewNode

func NewNode() *Node

NewNode initialises a Node object, with the Path and HandlerFn configured using a builder pattern

func (*Node) Field

func (n *Node) Field(name string) *Node

Field adds a struct field to the Node path, identified by the name of the struct

func (*Node) Handle

func (n *Node) Handle(from, to interface{}) error

Handle invokes the stored HandlerFn with the current and desired resource states

func (*Node) Handler

func (n *Node) Handler(f func(from, to interface{}, path *Node) error) *Node

Handler adds a HandlerFn to the Node which will be invoked when the Handle() method is called

func (*Node) Index

func (n *Node) Index(id int) *Node

Index adds a specific slice/array index to the Node path

func (*Node) Key

func (n *Node) Key(key interface{}) *Node

Key adds a key value to the Node path, keys are type dependent

type NodeDetail

type NodeDetail struct {
	Field string
	Index int
	Key   interface{}
	Type  string
}

NodeDetail describes an individual node in the path to the target Node above, navigating the object graph via struct fields, map keys or slice/array indices.

type Registry

type Registry struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Registry stores a list of change nodes to be evaluated

func NewRegistry

func NewRegistry() *Registry

NewRegistry initialises an empty change Registry with a default logger

func (*Registry) Add

func (r *Registry) Add(n *Node)

Add a new change node to the Registry

func (*Registry) HandleChanges

func (r *Registry) HandleChanges(from, to interface{}) error

HandleChanges invokes the change handler for all stored change nodes

func (*Registry) SetLogger

func (r *Registry) SetLogger(logger hclog.Logger)

SetLogger overrides the default logger

Jump to

Keyboard shortcuts

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