Documentation
¶
Overview ¶
Copyright (c) Walmart Inc.
This source code is licensed under the Apache 2.0 license found in the LICENSE file in the root directory of this source tree.
Copyright (c) Walmart Inc.
This source code is licensed under the Apache 2.0 license found in the LICENSE file in the root directory of this source tree.
Copyright (c) Walmart Inc.
This source code is licensed under the Apache 2.0 license found in the LICENSE file in the root directory of this source tree.
Copyright (c) Walmart Inc.
This source code is licensed under the Apache 2.0 license found in the LICENSE file in the root directory of this source tree.
Copyright (c) Walmart Inc.
This source code is licensed under the Apache 2.0 license found in the LICENSE file in the root directory of this source tree.
Index ¶
- func CopyReflectValue(oldVal reflect.Value) (newVal reflect.Value)
- func CopyValueReflectively(oldValue interface{}) interface{}
- type ChangeSet
- func (cs *ChangeSet) AddPathAddition(ctx []PathElement, newValue reflect.Value)
- func (cs *ChangeSet) AddPathChange(ctx []PathElement, oldValue reflect.Value, newValue reflect.Value)
- func (cs *ChangeSet) AddPathDeletion(ctx []PathElement, oldValue reflect.Value)
- func (cs ChangeSet) Equals(other ChangeSet) bool
- func (cs ChangeSet) Patch(obj interface{}) (err error)
- func (cs ChangeSet) String() string
- type ObjectPath
- func (op *ObjectPath) Append(newVal reflect.Value)
- func (op *ObjectPath) AppendNew(newType reflect.Type)
- func (op *ObjectPath) CreateIfMissing()
- func (op *ObjectPath) Delete()
- func (op *ObjectPath) GetField() reflect.Value
- func (op *ObjectPath) GetIndex() reflect.Value
- func (op *ObjectPath) GetMapValue() reflect.Value
- func (op *ObjectPath) InBounds() bool
- func (op *ObjectPath) IsPointer() bool
- func (op ObjectPath) LastVal() reflect.Value
- func (op *ObjectPath) NeedsAppend() bool
- func (op *ObjectPath) Next() (hasNext bool)
- func (op ObjectPath) PathElem() PathElement
- func (op *ObjectPath) Set(newVal reflect.Value)
- func (op *ObjectPath) SetMapValue(newValue reflect.Value)
- func (op *ObjectPath) SetMapValueToNew(newType reflect.Type)
- func (op *ObjectPath) SetToNew(newType reflect.Type)
- type ObjectPathConfig
- Bugs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyReflectValue ¶
Reflectively and recursively makes a copy of a reflect.Value.
func CopyValueReflectively ¶
func CopyValueReflectively(oldValue interface{}) interface{}
Reflectively make a copy of an object. This uses reflection to traverse an object and create a copy.
Types ¶
type ChangeSet ¶
A ChangeSet represents the result of a diff as a set of Changes against a Base Type.
func Diff ¶
Computes the change set between two objects, both objects must have the same type. This returns a ChangeSet on success and an error on failure.
func (*ChangeSet) AddPathAddition ¶
Add an addition to this change set.
func (*ChangeSet) AddPathChange ¶
func (cs *ChangeSet) AddPathChange(ctx []PathElement, oldValue reflect.Value, newValue reflect.Value)
Add a change to this change set.
func (*ChangeSet) AddPathDeletion ¶
Add a delete to this change set.
func (ChangeSet) Equals ¶
Compares this ChangeSet against another ChangeSet, returns true if the are the same. This is currently used only in the testing framework, but could have other uses.
type ObjectPath ¶
type ObjectPath struct { reflect.Value Path []PathElement // contains filtered or unexported fields }
An Object path provides a way to step through a given []PathElement as it relates to object given at creation and take actions at each point along the way. At any given point the ObjectPath can be used as a reflect.Value at the current point in the traversal of path.
func NewObjectPathWithConfig ¶
func NewObjectPathWithConfig(root reflect.Value, path []PathElement, config ObjectPathConfig) *ObjectPath
Creates an Object path, if root is not writable then mutating actions on the resulting ObjectPath will panic. The path is a list of PathElements to follow when traversing root. Finally config contains options and actions that ObjectPath can take for you automatically.
func (*ObjectPath) Append ¶
func (op *ObjectPath) Append(newVal reflect.Value)
Appends to the current Slice a newValue. Panics if newValue is not assignable to the Slice type.
func (*ObjectPath) AppendNew ¶
func (op *ObjectPath) AppendNew(newType reflect.Type)
Appends to the current Slice a new object of newType. Panics if newType is not assignable to the Slice type.
func (*ObjectPath) CreateIfMissing ¶
func (op *ObjectPath) CreateIfMissing()
Create the next object in the path if it does not currently exist.
func (*ObjectPath) Delete ¶
func (op *ObjectPath) Delete()
Delete the object at the current point in the path. Delete is only supported for Map, Slice, and Ptr; panics otherwise.
func (*ObjectPath) GetField ¶
func (op *ObjectPath) GetField() reflect.Value
Retrieve the next from a Struct type. Panics if the current object is not a Struct.
func (*ObjectPath) GetIndex ¶
func (op *ObjectPath) GetIndex() reflect.Value
Retrieves the next index. Panics if the current object is not an Array or Slice.
func (*ObjectPath) GetMapValue ¶
func (op *ObjectPath) GetMapValue() reflect.Value
Retrieves the value for the next key. Panics if the current object is not a Map.
func (*ObjectPath) InBounds ¶
func (op *ObjectPath) InBounds() bool
Returns true if the next index exists in the current Slice or Array. Panics if current element is not a Slice or Array.
func (*ObjectPath) IsPointer ¶
func (op *ObjectPath) IsPointer() bool
Returns true if the current PathElement is a pointer.
func (ObjectPath) LastVal ¶
func (op ObjectPath) LastVal() reflect.Value
Retrieve the last value of this ObjectPath.
func (*ObjectPath) NeedsAppend ¶
func (op *ObjectPath) NeedsAppend() bool
Returns true if the next index is at the end of a Slice. This means that an append will be successful at this point.
func (*ObjectPath) Next ¶
func (op *ObjectPath) Next() (hasNext bool)
Advance to the next object in the path. Returns true if there are further elements in the path, and false otherwise.
func (ObjectPath) PathElem ¶
func (op ObjectPath) PathElem() PathElement
Retrieve the current Path Element.
func (*ObjectPath) Set ¶
func (op *ObjectPath) Set(newVal reflect.Value)
Set the current value to newValue. Panics if newValue is not assignable to the current value.
func (*ObjectPath) SetMapValue ¶
func (op *ObjectPath) SetMapValue(newValue reflect.Value)
Sets the next map key to the given value. Panics if the newValue is not assignable to the Map value.
func (*ObjectPath) SetMapValueToNew ¶
func (op *ObjectPath) SetMapValueToNew(newType reflect.Type)
Sets the next map key to the value of a new reflect.Type. Panics if newType is not assignable to the Map value.
func (*ObjectPath) SetToNew ¶
func (op *ObjectPath) SetToNew(newType reflect.Type)
Set the current value to an instance of newType. Panics if newType is not assignable to the current value.
type ObjectPathConfig ¶
type ObjectPathConfig struct { // If the path would traverse into an object (struct, map, // array, slice, pointer) that does not exist, create it. CreateMissingObjects bool // If the path traverses into an invalid Map key or Slice // index, create the object that should be there. CreateMissingValues bool }
Notes ¶
Bugs ¶
Renaming of Map keys results in a deletion and addition.
Lists with different orders but the same elements will generate changes.