cmp

package
v0.0.0-...-947b840 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TAG_OPTION_ID = "id"
)

Variables

This section is empty.

Functions

func TriggerEvents

func TriggerEvents[E TriggerEvent](n *DiffNode, events []E)

TriggerEvents calls Trigger function of each detected event.

func TriggerEventsF

func TriggerEventsF[E Event](n *DiffNode, events []E, trigger TriggerFunc[E])

TriggerEventsF calls trigger function for each detected event.

Types

type ActionType

type ActionType string
const (
	UNKNOWN ActionType = ""
	NONE    ActionType = "none"
	CREATE  ActionType = "create"
	DELETE  ActionType = "delete"
	MODIFY  ActionType = "modify"
)

type Change

type Change struct {
	Path        string
	StructPath  string
	GenericPath string
	Before      interface{}
	After       interface{}
	Type        reflect.Type
	Kind        reflect.Kind
	Action      ActionType
}

func (Change) String

func (c Change) String() string

String returns change as a string.

type Changes

type Changes []Change

func ConflictingChanges

func ConflictingChanges[E Event](n *DiffNode, events []E) Changes

ConflictingChanges returns changes that are either excluded from all given events or have a conflicting actions (but their paths match).

func MatchingChanges

func MatchingChanges[E Event](n *DiffNode, events []E) Changes

MatchingChanges returns changes that match (trigger) given events.

func (Changes) String

func (cs Changes) String() string

String returns all changes as a string.

type Comparator

type Comparator struct {
	Tag                 string
	ExtraNameTags       []string
	RespectSliceOrder   bool // Compares slices by index
	IgnoreEmptyChanges  bool // Ignore leafs with "nil -> nil" value
	PopulateStructNodes bool // By default, before and after values are set only for leafs
}

func NewComparator

func NewComparator() *Comparator

func (*Comparator) Compare

func (c *Comparator) Compare(a, b interface{}) (*DiffNode, error)

Compare compares the given values and returns a comparison tree.

type CompareFunc

type CompareFunc func(reflect.Value, reflect.Value) (*DiffNode, error)

type DiffNode

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

func Compare

func Compare(a, b interface{}) (*DiffNode, error)

Compare initializes default comparator, compares given values and returns a comparison tree.

func NewEmptyNode

func NewEmptyNode(t reflect.Type, k reflect.Kind) *DiffNode

func NewNilNode

func NewNilNode() *DiffNode

func (*DiffNode) Changes

func (n *DiffNode) Changes() Changes

Changes returns list of changes extracted from the comparison node.

func (*DiffNode) ToYaml

func (n *DiffNode) ToYaml() string

ToYaml returns comparison result in YAML like format.

func (*DiffNode) ToYamlDiff

func (n *DiffNode) ToYamlDiff() string

ToYamlDiff returns only differences of the comparison in YAML like format.

type Event

type Event interface {
	Action() ActionType // Affected action
	Paths() []string    // Affected paths
}

type Pair

type Pair struct {
	A *reflect.Value
	B *reflect.Value
	// contains filtered or unexported fields
}

type Pairs

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

func NewPairs

func NewPairs(t reflect.Type) Pairs

type TriggerEvent

type TriggerEvent interface {
	Event
	Trigger(Change)
}

type TriggerFunc

type TriggerFunc[E Event] func(E, Change)

type TypeMismatchError

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

TypeMismatchError represents a type mismatch error when comparing two values of different types.

func NewTypeMismatchError

func NewTypeMismatchError(aKind, bKind reflect.Kind) *TypeMismatchError

func (*TypeMismatchError) Error

func (e *TypeMismatchError) Error() string

Jump to

Keyboard shortcuts

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