go-diff

A Go library for computing text differences, fuzzy string matching, and applying patches, ported from Google's diff-match-patch.

Library
Go
vv1.4.0
2,086stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
42/100Fair
Development Activity0
Maintenance0
Community68
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
57/100Fair
Architecture74
Code Quality72
Innovation40
Learning Curve40

go-diff is a Go port of Neil Fraser’s Diff, Match and Patch library originally written at Google. It implements three related text-synchronization algorithms in a single package: computing the differences between two texts, performing fuzzy matching to locate a pattern inside a larger body of text even when it has shifted or been edited, and generating and applying patches that tolerate drift in the surrounding content.

The library exposes its functionality through a single diffmatchpatch package built around a DiffMatchPatch configuration struct, keeping the public API small and centered on a handful of well-named entry points (DiffMain, MatchMain, PatchMake, PatchApply). It has been stable for over a decade and is used as a dependency inside several widely used Go tools that need text-diffing primitives without shelling out to an external diff binary.

What You Get

  • Character-level diff computation between two strings via DiffMain, built on the classic Myers diff algorithm
  • Diff cleanup passes (DiffCleanupSemantic, DiffCleanupEfficiency) that merge and simplify raw diffs into more human-readable output
  • Bitap-based fuzzy string matching (MatchMain/MatchBitap) for locating an approximate match within a larger text
  • Patch creation and fuzzy-tolerant patch application (PatchMake/PatchApply) that can still apply patches when surrounding text has drifted
  • Diff serialization helpers (DiffToDelta/DiffFromDelta) for encoding diffs as compact, transportable delta strings
  • Pretty-printing helpers (DiffPrettyHtml/DiffPrettyText) for rendering diffs as HTML or ANSI-colored terminal text

Common Use Cases

  • Building git-style merge or version-diff tooling that needs to compute and visualize text changes
  • Synchronizing concurrent edits in collaborative text editors via fuzzy patch application
  • Implementing fuzzy search or spell-check style lookups against noisy or imperfect text
  • Rendering human-readable diff output in CI bots, review tools, or documentation generators

Under The Hood

Architecture go-diff is organized as a single diffmatchpatch package whose methods hang off a DiffMatchPatch configuration struct (timeouts, match thresholds, patch margins) created via New(). The three algorithm families share one data model: diff.go implements the core text-diffing routines (a recursive divide-and-conquer diff with a bisect fallback) and produces []Diff values; match.go implements a bitwise bitap fuzzy-search independent of the diff code; patch.go builds directly on the Diff/Operation types to construct and fuzzy-apply Patch values. There is no dependency injection or internal layering beyond this — it’s a flat, functional core threaded through the config struct as a receiver, so a change to the shared Diff/Operation representation would ripple into both the match and patch modules that consume it.

Tech Stack The library has zero runtime dependencies outside the Go standard library, drawing only on packages like strings, regexp, unicode/utf8, net/url, and time for its core logic. Test-only dependencies (testify, go-spew, kr/pretty, check.v1, yaml.v2) are pulled in transitively for assertions. The module targets Go 1.13, builds via a Makefile that wraps go test/golint/errcheck, and CI runs on Travis across Go 1.13-1.15 on Linux and macOS — a legacy CI setup with no modern GitHub Actions workflow present.

Code Quality Core algorithm files are backed by substantial table-driven test suites (diff_test.go alone runs to over 1,500 lines, with further coverage for matching, patching, and string utilities), using testify for assertions in the idiomatic Go testing style. Error handling is explicit via Go’s (value, error) return convention where applicable (e.g. PatchFromText), with no swallowed errors observed in the core files reviewed. Naming and structure follow standard Go conventions, and a go:generate directive drives stringer for the Operation enum. Linting is wired through a Makefile script rather than a modern CI-enforced pipeline.

What Makes It Unique go-diff is not a novel algorithm — it’s a faithful, long-maintained Go port of Google’s original 2006 diff-match-patch library, the same reference implementation ported to many other languages. Its value for Go users is being a dependency-free, in-process alternative to shelling out to a diff binary, bundling text diffing, fuzzy matching, and fuzzy patch application behind one small, stable API rather than breaking novel algorithmic ground.

Used by 5 apps in this directory

Go
79%
Apache 2.0

Dolt

Databases · Data Engineering · Developer Tools

24,372

The SQL database you can branch, merge, diff, and clone — Git for your data, MySQL-compatible and ready for multi-agent AI workflows.

View details
91
Repo Health
9
Technical
65
Dependency
Built with
Go79%
Shell20%
Updated yesterday
TypeScript
54%
Other

Focalboard

Productivity · Project Management · Collaboration

26,448

Self-hosted, open source project management with Kanban, table, gallery, and calendar views — a privacy-first alternative to Trello, Notion, and Asana.

View details
57
Repo Health
82
Technical
64
Dependency
Built with
TypeScript54%
Go40%
Updated 3 months ago
Go
83%
MIT

Gitea

Devops · Developer Tools · Project Management

57,850

Self-hosted DevOps in a single Go binary — Git hosting, GitHub Actions-compatible CI/CD, and 30+ package registries without any SaaS dependency.

View details
93
Repo Health
79
Technical
64
Dependency
Built with
Go83%
Updated today
Go
68%
MIT

Gogs

Developer Tools

47,807

The painless self-hosted Git service that runs on anything from a Raspberry Pi to a $5 cloud droplet, delivering GitHub-like workflows as a single Go binary.

View details
89
Repo Health
79
Technical
71
Dependency
Built with
Go68%
Go Template16%
TypeScript10%
Updated yesterday
Go
95%
MIT

cli

Developer Tools · Team Chat

17,039

The official Lark/Feishu CLI tool built for both humans and AI agents, delivering 200+ commands and 26 AI agent skills across 18 business domains from messaging and calendar to docs, sheets, and approvals.

View details
82
Repo Health
83
Technical
74
Dependency
Built with
Go95%
Updated 2 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search