go-cmp Documentation

repository·master·Indexed 26 days ago

https://github.com/google/go-cmp

A Go package for semantic equality comparisons of Go values, providing a safer and more powerful alternative to reflect.DeepEqual. It supports custom equality functions, method-based equality via Equal methods, recursive comparison of primitive kinds, and explicit handling of unexported fields.

Tokens
238
Snippets
1
Records
2
Agent score
39%

What's inside go-cmp

  1. Compare Go values with cmp

    master

    The cmp package provides a powerful and safer alternative to reflect.DeepEqual for determining if two values are semantically equal.

    Key capabilities include:

    • Custom Equality: Use custom equality functions to override default behavior (e.g., comparing floats within a specific tolerance).
    • Method-based Equality: If a type defines an Equal method, cmp will use it to determine equality.
    • Recursive Comparison: If no custom options or Equal methods are present, it recursively compares primitive kinds.
    • Unexported Field Safety: Unlike reflect.DeepEqual, cmp does not compare unexported fields by default. Attempting to compare them will cause a panic unless you explicitly handle them using cmpopts.IgnoreUnexported or the AllowUnexported option.