https://github.com/kilianpaquier/compare
Compare files and directories with Golang internal diff library
https://github.com/kilianpaquier/compare
compare-directories compare-files compare-text golang golang-library
Last synced: 5 months ago
JSON representation
Compare files and directories with Golang internal diff library
- Host: GitHub
- URL: https://github.com/kilianpaquier/compare
- Owner: kilianpaquier
- License: mit
- Created: 2025-01-08T18:39:58.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2026-01-10T20:43:40.000Z (5 months ago)
- Last Synced: 2026-01-11T06:16:41.565Z (5 months ago)
- Topics: compare-directories, compare-files, compare-text, golang, golang-library
- Language: Go
- Homepage: https://pkg.go.dev/github.com/kilianpaquier/compare
- Size: 140 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# compare
---
- [How to use ?](#how-to-use-)
- [Documentation](#documentation)
## How to use ?
```sh
go get github.com/kilianpaquier/compare
```
## Documentation
Can be found here in a better format: https://pkg.go.dev/github.com/kilianpaquier/compare.
```go
/*
Package compare exposes two functions to compare directories and files between them.
Returned errors can be easily printed to get a easy visual on diffs.
All diffs are done with Golang internal diff library: https://github.com/golang/go/blob/master/src/internal/diff/diff.go
Kindly exported and maintained by go-internal: https://github.com/rogpeppe/go-internal/blob/master/diff/diff.go
Diffs are under the form of:
diff path/to/expected.txt path/to/actual.txt
--- path/to/expected.txt
+++ path/to/actual.txt
@@ -1,1 +1,1 @@
-Some text value that should be equal to the expected one.
\ No newline at end of file
+Some text value that should be equal to the expected one
\ No newline at end of file
Examples:
func main() {
expected := "path/to/expected.txt"
actual := "path/to/actual.txt"
err := compare.Files(expected, actual)
// handle err
}
func main() {
expected := "path/to/expected"
actual := "path/to/actual"
err := compare.Dirs(expected, actual)
// handle err
}
func main() {
expected := "expected content (only useful on multiline contents with the desire to get a pretty diff)"
actual := "actual content (only useful on multiline contents with the desire to get a pretty diff)"
err := compare.Contents(expected, actual)
// handle err
}
*/
package compare
```