Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different representation of a diff? #14

Open
decibel opened this issue Oct 11, 2017 · 2 comments
Open

Different representation of a diff? #14

decibel opened this issue Oct 11, 2017 · 2 comments

Comments

@decibel
Copy link

decibel commented Oct 11, 2017

I came across this project while looking for a simple way to compare two instances of the same struct. I currently define type Delta struct{ old, new interface{} } and then use a map of that where the member name is the key. Obviously can't do deep compares with that, but it works well from a programmatic standpoint.

I'm wondering if you considered any other methods for handling the paths? Would you be interested in having any alternative representations in this project?

@d4l3k
Copy link
Owner

d4l3k commented Nov 2, 2017

Haven't really given it much thought. What's the benefit of having a struct like that? Are you actually using the diff for something other than just pretty printing it?

@decibel
Copy link
Author

decibel commented Nov 17, 2017

Right, I'm using the diff as a way to represent a set of requested changes. I've got code for this, but I need to get approval to share it. In a nutshell though, I've created interface {Old(),New() interface{}}, an interface on top of that that adds addressability (for arrays/slices, as well as maps/structs), and then a MapDeltas struct that will store a set of those. The interfaces also have methods like Equal(), Added/Removed (when something was added or removed from a slice or map) and a few other goodies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants