Documentation
¶
Overview ¶
Package deep provides function deep.Equal which is like reflect.DeepEqual but returns a list of differences. This is helpful when comparing complex types like structures and maps.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // FloatPrecision is the number of decimal places to round float values // to when comparing. FloatPrecision = 10 // MaxDiff specifies the maximum number of differences to return. MaxDiff = 10 // MaxDepth specifies the maximum levels of a struct to recurse into. MaxDepth = 10 // LogErrors causes errors to be logged to STDERR when true. LogErrors = false // CompareUnexportedFields causes unexported struct fields, like s in // T{s int}, to be comparsed when true. CompareUnexportedFields = false )
var ( // ErrMaxRecursion is logged when MaxDepth is reached. ErrMaxRecursion = errors.New("recursed to MaxDepth") // ErrTypeMismatch is logged when Equal passed two different types of values. ErrTypeMismatch = errors.New("variables are different reflect.Type") // ErrNotHandled is logged when a primitive Go kind is not handled. ErrNotHandled = errors.New("cannot compare the reflect.Kind") )
var DefaultComparer = makeDefaultComparer()
Functions ¶
func Equal ¶
func Equal(a, b interface{}) []string
Equal compares variables a and b, recursing into their structure up to MaxDepth levels deep, and returns a list of differences, or nil if there are none. Some differences may not be found if an error is also returned.
If a type has an Equal method, like time.Equal, it is called to check for equality.
Types ¶
type Comparer ¶ added in v1.0.2
type Comparer struct {
FloatPrecision *int
MaxDiff *int
MaxDepth *int
LogErrors *bool
CompareUnexportedFields *bool
ErrMaxRecursion *error
ErrTypeMismatch *error
ErrNotHandled *error
}
Comparer is a struct capturing the configuration used for Equals(). The package Equal() function uses a default Comparer struct which references the global variables that control the execution of the equality algorithm.
func MakeComparer ¶ added in v1.0.2
MakeComparer returns a Comparer struct with nil fields initialized to point to the global settings.