Skip to content

Commit

Permalink
Slight modification to diff tracker to use String() with structs when…
Browse files Browse the repository at this point in the history
… available
  • Loading branch information
Jason Raede committed May 5, 2015
1 parent c27b84a commit 427d480
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions difftracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ func isNilOrInvalid(f reflect.Value) bool {
return (!f.IsValid())
}

type Stringer interface {

This comment has been minimized.

Copy link
@sharpner

sharpner May 6, 2015

why not use fmt.Stringer ?

This comment has been minimized.

Copy link
@jraede

jraede May 6, 2015

Collaborator

Good question. Didn't realize that was defined in fmt.

This comment has been minimized.

Copy link
@sharpner

sharpner May 6, 2015

yeah it's hidden pretty well :D

String() string
}

func GetChangedFields(struct1 interface{}, struct2 interface{}, useBson bool) ([]string, error) {

diffs := make([]string, 0)
Expand Down Expand Up @@ -198,11 +202,11 @@ func GetChangedFields(struct1 interface{}, struct2 interface{}, useBson bool) ([
childDiffs = getFields(childType)

} else {
// Special for time.Time and bson.ObjectId
if strings.HasSuffix(childType.String(), "time.Time") || strings.HasSuffix(childType.String(), "bson.ObjectId") {
if _, ok := field1.Interface().(Stringer); ok {
if fmt.Sprint(field1.Interface()) != fmt.Sprint(field2.Interface()) {
diffs = append(diffs, fieldName)
}

} else {
childDiffs, err = GetChangedFields(field1.Interface(), field2.Interface(), useBson)

Expand Down

0 comments on commit 427d480

Please sign in to comment.