How google/go-cmp works
go-cmp is a Go library for semantic equality and human-readable differences, intended as a safer, more configurable alternative to reflect.DeepEqual. Callers provide two values and optional comparison rules; the library compares recursively, then can render differences. Its documented capabilities include custom comparers, Equal methods, primitive-kind comparison, and options for ignoring unexported fields. The graph separates option construction, comparison, slice-diff support, and report formatting. Evidence is limited to the README and indexed or excerpted source; some internal call details were not sampled.
Main entry points: options.go Option processing · compare.go Recursive comparison · value Value helpers · report_slices.go Slice and text diffs
Components 17
Public API
- Equal and Diff
cmp/compare.go
Comparison Engine
- Recursive comparison
cmp/compare.go - Value helpers
cmp/internal/value - Function checks
cmp/internal/function/func.go - Edit-script algorithm
cmp/internal/diff/diff.go
Comparison Options
- Option processing
cmp/options.go - Equivalence rules
cmp/cmpopts/equate.go - Ignore filters
cmp/cmpopts/ignore.go - Sort transforms
cmp/cmpopts/sort.go - Struct filters
cmp/cmpopts/struct_filter.go - Custom transforms
cmp/cmpopts/xform.go
Difference Reports
- Comparison paths
cmp/path.go - Value rendering
cmp/report_reflect.go - Reference rendering
cmp/report_references.go - Slice and text diffs
cmp/report_slices.go - Text formatting
cmp/report_text.go
Other components
- Go caller
Connections 18
- Go caller → Equal and Diff: compares values
README.md - Equal and Diff → Recursive comparison: runs comparison
cmp/compare.go - Recursive comparison → Option processing: processes options
cmp/compare.go - Recursive comparison → Edit-script algorithm: uses edit scripts
cmp/compare.go - Recursive comparison → Function checks: validates functions
cmp/compare.go - Recursive comparison → Value helpers: uses helpers
cmp/compare.go - Option processing → Function checks: checks callbacks
cmp/options.go - Equivalence rules → Option processing: creates options
cmp/cmpopts/equate.go - Ignore filters → Option processing: creates filters
cmp/cmpopts/ignore.go - Sort transforms → Option processing: creates transforms
cmp/cmpopts/sort.go - Struct filters → Option processing: creates filters
cmp/cmpopts/struct_filter.go - Custom transforms → Option processing: creates transforms
cmp/cmpopts/xform.go - Equal and Diff → Slice and text diffs: produces differences
cmp/compare.go - Comparison paths → Value helpers: uses helpers
cmp/path.go - Value rendering → Value helpers: uses helpers
cmp/report_reflect.go - Reference rendering → Value helpers: uses helpers
cmp/report_references.go - Slice and text diffs → Edit-script algorithm: computes slice edits
cmp/report_slices.go - Text formatting → Slice and text diffs: formats diff text