r3labs / diff

A library for diffing golang structures
Mozilla Public License 2.0
888 stars 80 forks source link

Support for custom differs #26

Closed lovromazgon closed 4 years ago

lovromazgon commented 4 years ago

This PR adds support for defining custom diff functions.

The use case is to add custom diff functions for specific types (see test) or to extend support for unsupported types (e.g. uuid.UUID is currently not supported, also zero value needs special treatment). It could even be used to override default diff functions with custom ones.

Sidenote: The sole purpose of MutableChangelog is to expose the internal method add on Changelog without changing the interface of that type. The code could be a bit simpler if you decide to just expose Changelog.add.

Let me know if you want me to add an entry in the readme describing this feature.

purehyperbole commented 4 years ago

Hey @lovromazgon, very sorry for the late review of this. This looks like a great feature. I'm more than happy to merge this.

Only things that would benefit from a change would be exposing changelog.Add as a public function (as you suggested), as well as expose AreType to help with implementing the Match function.

lovromazgon commented 4 years ago

@purehyperbole glad to hear you like the feature, I added the changes you requested.

purehyperbole commented 4 years ago

Awesome, thanks for the contribution!