Documentation ¶
Index ¶
- func JSONDiff(before, after any, opts *DiffOptions) (map[string]FieldChange, error)
- func MustToJSON(v any) map[string]any
- func MustToJSONString(v any) string
- func ToJSON(v any) (map[string]any, error)
- func ToJSONString(v any) (string, error)
- type ChangeType
- type Comparator
- type DiffOptions
- type FieldChange
- type FieldType
- type JSONConverter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JSONDiff ¶
func JSONDiff(before, after any, opts *DiffOptions) (map[string]FieldChange, error)
JSONDiff compares two structs and returns a map of the changes
func MustToJSON ¶
MustToJSON converts any struct to a map[string]any, panics on error Use this only when you're absolutely certain the conversion won't fail
func MustToJSONString ¶
MustToJSONString converts any struct to a JSON string, panics on error Use this only when you're absolutely certain the conversion won't fail
func ToJSONString ¶
ToJSONString converts any struct to a JSON string
Types ¶
type ChangeType ¶
type ChangeType string
ChangeType represents the type of change that occurred
const ( ChangeTypeCreated ChangeType = "created" ChangeTypeUpdated ChangeType = "updated" ChangeTypeDeleted ChangeType = "deleted" )
type Comparator ¶
Comparator is a function type that defines custom comparison logic
type DiffOptions ¶
type DiffOptions struct { IgnoreFields []string // Fields to ignore during comparison CustomComparors map[string]Comparator MaxDepth int // Maximum depth for nested object comparison IgnoreCase bool // Whether to ignore case in string comparisons }
DiffOptions provides configuration options for the diff operation
func DefaultOptions ¶
func DefaultOptions() *DiffOptions
DefaultOptions returns the default DiffOptions
type FieldChange ¶
type FieldChange struct { From any `json:"from"` To any `json:"to"` Type ChangeType `json:"type"` FieldType FieldType `json:"fieldType"` Path string `json:"path"` }
FieldChange represents a change in a single field with additional metadata
type FieldType ¶
type FieldType string
FieldType represents the data type of the field
const ( FieldTypeString FieldType = "string" FieldTypeNumber FieldType = "number" FieldTypeBoolean FieldType = "boolean" FieldTypeArray FieldType = "array" FieldTypeObject FieldType = "object" FieldTypeDateTime FieldType = "datetime" FieldTypeNull FieldType = "null" FieldTypeUndefined FieldType = "undefined" )