diff

package
v0.19.1012 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Diff

type Diff struct {
	Key      string   `json:"key"`
	Diff     *DiffKey `json:"diff,omitempty"`
	Children []*Diff  `json:"children,omitempty"`
}

func MapDiff added in v0.19.1012

func MapDiff(key string, old, new map[string]string) *Diff

MapDiff diffs two map[string]string values, returning a parent node with per-key children. Returns nil if both maps are empty/nil.

func NewDiff

func NewDiff(opts ...DiffOption) *Diff

func (*Diff) FormatChanged added in v0.19.1012

func (d *Diff) FormatChanged(indent string) string

FormatChanged returns only the parts of the diff tree that have changes (added, removed, or changed). Unchanged fields and sections are omitted entirely.

func (*Diff) String

func (d *Diff) String(indent string) string

String returns the full diff tree with +/-/~ prefixes indicating added, removed, changed, and unchanged fields. Empty unchanged fields (both old and new are "") are suppressed.

func (*Diff) Summary

func (d *Diff) Summary() DiffSummary

type DiffKey

type DiffKey struct {
	Op   Op     `json:"op"`
	Diff string `json:"diff"`
}

type DiffOption

type DiffOption func(*Diff)

func WithBoolDiff added in v0.19.1012

func WithBoolDiff(old, new bool) DiffOption

WithBoolDiff creates a DiffOption that compares two bool values.

func WithChildren

func WithChildren(children ...*Diff) DiffOption

func WithKey

func WithKey(key string) DiffOption

func WithOptionalBoolDiff added in v0.19.1012

func WithOptionalBoolDiff(old, new *bool) DiffOption

WithOptionalBoolDiff creates a DiffOption that compares two *bool values, treating nil as false.

func WithOptionalStringDiff added in v0.19.1012

func WithOptionalStringDiff(old, new *string) DiffOption

WithOptionalStringDiff creates a DiffOption that compares two *string values, treating nil as empty string.

func WithStringDiff

func WithStringDiff(old, new string) DiffOption

func WithStringSliceDiff added in v0.19.1012

func WithStringSliceDiff(old, new []string) DiffOption

WithStringSliceDiff creates a DiffOption that compares two string slices by sorting and joining them.

type DiffSummary

type DiffSummary struct {
	HasChanged bool `json:"has_changed"`
	Added      int  `json:"added"`
	Removed    int  `json:"removed"`
	Changed    int  `json:"changed"`
	Unchanged  int  `json:"unchanged"`
}

type Diffable

type Diffable interface {
	Diff() (string, Op)
}

type Op

type Op string
const (
	OpAdd     Op = "add"
	OpRemove  Op = "remove"
	OpChange  Op = "change"
	OpNoop    Op = "noop"
	OpUnknown Op = ""
)

type StringDiffer

type StringDiffer struct {
	// contains filtered or unexported fields
}

func (*StringDiffer) Diff

func (d *StringDiffer) Diff() (string, Op)

Jump to

Keyboard shortcuts

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