structs

package
v1.32.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 3 Imported by: 0

README

Structs

  • CompareStructs: Compares two structs and returns the differences between them.

Examples:

For examples of each function, please checkout EXAMPLES.md


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	FieldName string
	OldValue  interface{}
	NewValue  interface{}
}

Result represents the comparison outcome of a field, including its name, old value, and new value.

func CompareStructs

func CompareStructs(old, new interface{}, prefix ...string) ([]Result, error)

CompareStructs compares two struct instances (or pointers to structs) and returns their differences.

Only fields explicitly tagged with `updatable` are compared. Supported tag formats:

  • `updatable:"true"` → uses the struct field name
  • `updatable:"custom_name"` → uses the custom field name in results

This function supports:

  • Structs and pointers to structs (including nil pointers)
  • Recursively comparing nested structs (excluding time.Time)
  • Comparing primitives, slices, arrays, maps, and pointers

If a field's value differs (based on reflect.DeepEqual), the field is added to the result.

The optional `prefix` is used for naming nested fields like `data.age`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL