Skip to content

Instantly share code, notes, and snippets.

@dmundt
Last active January 23, 2020 10:46
Show Gist options
  • Save dmundt/d0d47892942e9975112df995362cdd28 to your computer and use it in GitHub Desktop.
Save dmundt/d0d47892942e9975112df995362cdd28 to your computer and use it in GitHub Desktop.
Go: diffpatchmerge example usage
module example.com/m
go 1.13
require github.com/sergi/go-diff v1.1.0
package main
import (
"fmt"
"github.com/sergi/go-diff/diffmatchpatch"
)
const (
text1 = "Lorem ipsum dolor."
text2 = "Lorem dolor sit amet."
)
func main() {
dmp := diffmatchpatch.New()
diff := dmp.DiffMain(text1, text2, true)
dmp.DiffCleanupSemantic(diff)
patch := dmp.PatchMake(text1, text2, diff)
s := dmp.PatchToText(patch)
fmt.Println(s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment