diff

package
v0.19.1141 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: AGPL-3.0 Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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"`
	Before string `json:"before,omitempty"`
	After  string `json:"after,omitempty"`
}

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 WithContentDiff added in v0.19.1024

func WithContentDiff(old, new string) DiffOption

WithContentDiff creates a DiffOption for file-like content. It derives the op from presence (add when old is empty, remove when new is empty, change otherwise), stores a short label in Diff for text renderers, and carries the raw before/after contents so consumers can render a line-by-line diff.

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