diff --git a/diff_bool.go b/diff_bool.go index 2ab2a70..0e30503 100644 --- a/diff_bool.go +++ b/diff_bool.go @@ -8,12 +8,12 @@ import "reflect" func (d *Differ) diffBool(path []string, a, b reflect.Value, parent interface{}) error { if a.Kind() == reflect.Invalid { - d.cl.Add(CREATE, path, nil, b.Interface()) + d.cl.Add(CREATE, path, nil, exportInterface(b)) return nil } if b.Kind() == reflect.Invalid { - d.cl.Add(DELETE, path, a.Interface(), nil) + d.cl.Add(DELETE, path, exportInterface(a), nil) return nil } @@ -22,7 +22,7 @@ func (d *Differ) diffBool(path []string, a, b reflect.Value, parent interface{}) } if a.Bool() != b.Bool() { - d.cl.Add(UPDATE, path, a.Interface(), b.Interface(), parent) + d.cl.Add(UPDATE, path, exportInterface(a), exportInterface(b), parent) } return nil diff --git a/diff_float.go b/diff_float.go index 5fcf2e0..9494365 100644 --- a/diff_float.go +++ b/diff_float.go @@ -10,12 +10,12 @@ import ( func (d *Differ) diffFloat(path []string, a, b reflect.Value, parent interface{}) error { if a.Kind() == reflect.Invalid { - d.cl.Add(CREATE, path, nil, b.Interface()) + d.cl.Add(CREATE, path, nil, exportInterface(b)) return nil } if b.Kind() == reflect.Invalid { - d.cl.Add(DELETE, path, a.Interface(), nil) + d.cl.Add(DELETE, path, exportInterface(a), nil) return nil } @@ -25,7 +25,7 @@ func (d *Differ) diffFloat(path []string, a, b reflect.Value, parent interface{} if a.Float() != b.Float() { if a.CanInterface() { - d.cl.Add(UPDATE, path, a.Interface(), b.Interface(), parent) + d.cl.Add(UPDATE, path, exportInterface(a), exportInterface(b), parent) } else { d.cl.Add(UPDATE, path, a.Float(), b.Float(), parent) } diff --git a/diff_int.go b/diff_int.go index 77f7e64..3658bf7 100644 --- a/diff_int.go +++ b/diff_int.go @@ -10,12 +10,12 @@ import ( func (d *Differ) diffInt(path []string, a, b reflect.Value, parent interface{}) error { if a.Kind() == reflect.Invalid { - d.cl.Add(CREATE, path, nil, b.Interface()) + d.cl.Add(CREATE, path, nil, exportInterface(b)) return nil } if b.Kind() == reflect.Invalid { - d.cl.Add(DELETE, path, a.Interface(), nil) + d.cl.Add(DELETE, path, exportInterface(a), nil) return nil } @@ -25,7 +25,7 @@ func (d *Differ) diffInt(path []string, a, b reflect.Value, parent interface{}) if a.Int() != b.Int() { if a.CanInterface() { - d.cl.Add(UPDATE, path, a.Interface(), b.Interface(), parent) + d.cl.Add(UPDATE, path, exportInterface(a), exportInterface(b), parent) } else { d.cl.Add(UPDATE, path, a.Int(), b.Int(), parent) } diff --git a/diff_slice.go b/diff_slice.go index dff1fae..5441bc7 100644 --- a/diff_slice.go +++ b/diff_slice.go @@ -10,12 +10,12 @@ import ( func (d *Differ) diffSlice(path []string, a, b reflect.Value) error { if a.Kind() == reflect.Invalid { - d.cl.Add(CREATE, path, nil, b.Interface()) + d.cl.Add(CREATE, path, nil, exportInterface(b)) return nil } if b.Kind() == reflect.Invalid { - d.cl.Add(DELETE, path, a.Interface(), nil) + d.cl.Add(DELETE, path, exportInterface(a), nil) return nil } @@ -56,7 +56,7 @@ func (d *Differ) diffSliceGeneric(path []string, a, b reflect.Value) error { return nil } - return d.diffComparative(path, missing, a.Interface()) + return d.diffComparative(path, missing, exportInterface(a)) } func (d *Differ) diffSliceComparative(path []string, a, b reflect.Value) error { @@ -82,7 +82,7 @@ func (d *Differ) diffSliceComparative(path []string, a, b reflect.Value) error { } } - return d.diffComparative(path, c, a.Interface()) + return d.diffComparative(path, c, exportInterface(a)) } // keeps track of elements that have already been matched, to stop duplicate matches from occurring @@ -100,7 +100,7 @@ func (st *sliceTracker) has(s, v reflect.Value) bool { } x := s.Index(i) - if reflect.DeepEqual(x.Interface(), v.Interface()) { + if reflect.DeepEqual(exportInterface(x), exportInterface(v)) { (*st)[i] = true return true } @@ -124,7 +124,7 @@ func hasAtSameIndex(s, v reflect.Value, atIndex int) bool { // check the element in the slice at atIndex to see if it matches Value, if it is a valid index into the slice if atIndex < s.Len() { x := s.Index(atIndex) - return reflect.DeepEqual(x.Interface(), v.Interface()) + return reflect.DeepEqual(exportInterface(x), exportInterface(v)) } return false diff --git a/diff_string.go b/diff_string.go index abf28ce..74182e2 100644 --- a/diff_string.go +++ b/diff_string.go @@ -8,12 +8,12 @@ import "reflect" func (d *Differ) diffString(path []string, a, b reflect.Value, parent interface{}) error { if a.Kind() == reflect.Invalid { - d.cl.Add(CREATE, path, nil, b.Interface()) + d.cl.Add(CREATE, path, nil, exportInterface(b)) return nil } if b.Kind() == reflect.Invalid { - d.cl.Add(DELETE, path, a.Interface(), nil) + d.cl.Add(DELETE, path, exportInterface(a), nil) return nil } @@ -24,7 +24,7 @@ func (d *Differ) diffString(path []string, a, b reflect.Value, parent interface{ if a.String() != b.String() { if a.CanInterface() { // If a and/or b is of a type that is an alias for String, store that type in changelog - d.cl.Add(UPDATE, path, a.Interface(), b.Interface(), parent) + d.cl.Add(UPDATE, path, exportInterface(a), exportInterface(b), parent) } else { d.cl.Add(UPDATE, path, a.String(), b.String(), parent) } diff --git a/diff_struct.go b/diff_struct.go index a16e34c..bc9a496 100644 --- a/diff_struct.go +++ b/diff_struct.go @@ -59,7 +59,7 @@ func (d *Differ) diffStruct(path []string, a, b reflect.Value) error { continue } - err := d.diff(fpath, af, bf, a.Interface()) + err := d.diff(fpath, af, bf, exportInterface(a)) if err != nil { return err } @@ -108,7 +108,7 @@ func (d *Differ) structValues(t string, path []string, a reflect.Value) error { continue } - err := nd.diff(fpath, xf, af, a.Interface()) + err := nd.diff(fpath, xf, af, exportInterface(a)) if err != nil { return err } diff --git a/diff_time.go b/diff_time.go index 4f583ff..4275e4a 100644 --- a/diff_time.go +++ b/diff_time.go @@ -11,12 +11,12 @@ import ( func (d *Differ) diffTime(path []string, a, b reflect.Value) error { if a.Kind() == reflect.Invalid { - d.cl.Add(CREATE, path, nil, b.Interface()) + d.cl.Add(CREATE, path, nil, exportInterface(b)) return nil } if b.Kind() == reflect.Invalid { - d.cl.Add(DELETE, path, a.Interface(), nil) + d.cl.Add(DELETE, path, exportInterface(a), nil) return nil } @@ -25,11 +25,11 @@ func (d *Differ) diffTime(path []string, a, b reflect.Value) error { } // Marshal and unmarshal time type will lose accuracy. Using unix nano to compare time type. - au := a.Interface().(time.Time).UnixNano() - bu := b.Interface().(time.Time).UnixNano() + au := exportInterface(a).(time.Time).UnixNano() + bu := exportInterface(b).(time.Time).UnixNano() if au != bu { - d.cl.Add(UPDATE, path, a.Interface(), b.Interface()) + d.cl.Add(UPDATE, path, exportInterface(a), exportInterface(b)) } return nil diff --git a/diff_uint.go b/diff_uint.go index 5244b27..fbe133f 100644 --- a/diff_uint.go +++ b/diff_uint.go @@ -10,12 +10,12 @@ import ( func (d *Differ) diffUint(path []string, a, b reflect.Value, parent interface{}) error { if a.Kind() == reflect.Invalid { - d.cl.Add(CREATE, path, nil, b.Interface()) + d.cl.Add(CREATE, path, nil, exportInterface(b)) return nil } if b.Kind() == reflect.Invalid { - d.cl.Add(DELETE, path, a.Interface(), nil) + d.cl.Add(DELETE, path, exportInterface(a), nil) return nil } @@ -25,7 +25,7 @@ func (d *Differ) diffUint(path []string, a, b reflect.Value, parent interface{}) if a.Uint() != b.Uint() { if a.CanInterface() { - d.cl.Add(UPDATE, path, a.Interface(), b.Interface(), parent) + d.cl.Add(UPDATE, path, exportInterface(a), exportInterface(b), parent) } else { d.cl.Add(UPDATE, path, a.Uint(), b.Uint(), parent) }