Documentation
¶
Overview ¶
Package structdiff provides field-level struct comparison for Go.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Format ¶ added in v0.2.0
Format returns a human-readable multi-line string describing the changes. Each line has the form: Path: old → new For string values, the output wraps them in quotes.
func FormatJSON ¶ added in v0.2.0
FormatJSON returns a JSON representation of the changes as an array of objects, each with "path", "old", and "new" fields.
Types ¶
type Change ¶
type Change struct {
// Path is the dot-notation path to the changed field (e.g., "Address.City").
Path string
// Old is the value in the first struct.
Old any
// New is the value in the second struct.
New any
}
Change represents a single field difference between two structs.
func Compare ¶
Compare performs a deep, field-level comparison of two values and returns a slice of changes. It handles all primitive types, strings, slices, maps, nested structs, and pointers. Paths use dot notation (e.g., "Address.City") and bracket notation for indices (e.g., "Items[2].Name"). Returns nil if the values are equal.
type Option ¶
type Option func(*config)
Option configures comparison behavior.
func IgnoreTag ¶
IgnoreTag returns an Option that skips fields whose struct tag matches the given value. For example, IgnoreTag("diff:\"-\"") skips fields tagged with `diff:"-"`.
func OnlyFields ¶ added in v0.2.0
OnlyFields returns an Option that restricts comparison to only the specified field names. This is the opposite of Ignore.