/go-diff

A simple diff library for Go.

Primary LanguageGoMIT LicenseMIT

go-diff

A simple diff library for Go.

Usage

Install

Add go-diff to your project.

go get github.com/ktnyt/go-diff

Character diff

package main

import (
	"fmt"

	"github.com/ktnt/go-diff"
)

func main() {
	ops := diff.Diff("coelacanth", "pelican")

	// Output: copelaicanth
	fmt.Println(ops.Concat())
}

Line diff

package main

import (
	"fmt"

	"github.com/ktnt/go-diff"
)

func main() {
	ops := diff.LineDiff("foo\nbar\nbaz", "foo\nbaz\nbar")

	// Output:
	// |       foo
	// -       bar
	// |       baz
	// +       bar
	fmt.Println(ops.Join())
}