https://github.com/haritsfahreza/libra
Compare your data with ease
https://github.com/haritsfahreza/libra
audit-trail auditing deep-equal deep-equals difference go golang
Last synced: 5 months ago
JSON representation
Compare your data with ease
- Host: GitHub
- URL: https://github.com/haritsfahreza/libra
- Owner: haritsfahreza
- License: mit
- Created: 2018-11-18T16:32:22.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2023-06-11T18:42:55.000Z (almost 3 years ago)
- Last Synced: 2024-11-17T12:11:25.535Z (over 1 year ago)
- Topics: audit-trail, auditing, deep-equal, deep-equals, difference, go, golang
- Language: Go
- Homepage:
- Size: 49.8 KB
- Stars: 36
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://pkg.go.dev/github.com/haritsfahreza/libra)
[](https://circleci.com/gh/haritsfahreza/libra)
[](https://codecov.io/gh/haritsfahreza/libra)
[](https://goreportcard.com/report/github.com/haritsfahreza/libra)
[](LICENSE)
# libra
Libra is a Go library to compare the interface (struct, maps, etc) and spot the differences between two of them.
## Installing
```sh
$ go get -u github.com/haritsfahreza/libra
```
## Usage
```go
//Prepare the objects that you want to compare
oldPerson := Person{
Name: "Sudirman",
Age: 22,
Weight: float64(80),
IsMarried: true,
}
newPerson := Person{
Name: "Sudirman",
Age: 23,
Weight: float64(85),
IsMarried: true,
}
diffs, err := libra.Compare(context.Background(), oldPerson, newPerson)
if err != nil {
panic(err)
}
//Use the diffs array with your own purpose e.g. printout
for i, diff := range diffs {
fmt.Printf("#%d : ChangeType=%s Field=%s ObjectType=%s Old='%v' New='%v'\n", i, diff.ChangeType, diff.Field, diff.ObjectType, diff.Old, diff.New)
}
```
Please see [examples](https://pkg.go.dev/github.com/haritsfahreza/libra#ex-Compare--Struct) for the other usage references
### Comparing struct with private fields
Currently, we need to have `String` function to get the value of the struct with private fields since `reflect` library would not be able to compare them.
```go
type HiddenPerson struct {
name string
age int
}
func (h HiddenPerson) String() string {
return fmt.Sprintf("%s, %d", h.name, h.age)
}
```
## Contributing
Please read [CONTRIBUTING.md](https://github.com/haritsfahreza/libra/blob/master/CODE_OF_CONDUCT.md) for details on our code of conduct, and the process for submitting pull requests to us.
## Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/haritsfahreza/libra/tags).
## Authors
- **Harits Fahreza Christyonotoputra** - _Initial work_ - [haritsfahreza](https://github.com/haritsfahreza)
See also the list of [contributors](https://github.com/haritsfahreza/libra/contributors) who participated in this project.
## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
## Acknowledgments
- With `libra`, you can speed up your Go software development, especially when you build the object auditing and data versioning system.
- This project is inspired by [`Javers`](https://javers.org).