compare

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: GPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterComparisonKind

func RegisterComparisonKind(kind reflect.Kind, factory ComparisonFactory)

func RegisterComparisonType

func RegisterComparisonType(typ reflect.Type, factory ComparisonFactory)

func RegisterDefaultComparison

func RegisterDefaultComparison(factory ComparisonFactory) (replaced bool)

Types

type Comparison

type Comparison interface {
	Label() string
	HTMLDiff() (template.HTML, error)
	HasChanged() (bool, error)
}

func FieldComparison

func FieldComparison(ctx context.Context, label func(context.Context) string, fieldName string, modelMeta attrs.ModelMeta, old, new attrs.Definer) (Comparison, error)

func GetComparison

func GetComparison(ctx context.Context, typ any, label any, fieldname string, oldInstance, newInstance attrs.Definer) (Comparison, error)

func MultipleComparison

func MultipleComparison(ctx context.Context, comparisons ...Comparison) Comparison

type ComparisonFactory

type ComparisonFactory func(ctx context.Context, label func(context.Context) string, fieldName string, modelMeta attrs.ModelMeta, old, new attrs.Definer) (Comparison, error)

type ComparisonWrapper

type ComparisonWrapper interface {
	Comparison
	Unwrap() []Comparison
}

type DiffType

type DiffType string
const (
	DIFF_EQUALS  DiffType = "equals"
	DIFF_ADDED   DiffType = "added"
	DIFF_REMOVED DiffType = "removed"
)

type Differential

type Differential struct {
	Type  DiffType
	Value any
}

type TextDiff

type TextDiff struct {
	Changes   []Differential // list of changes
	Separator string         // e.g. " ", "\n", etc.
	Tagname   string         // e.g. "span", "div", etc.
	Unsafe    bool
}

func DiffText

func DiffText(a, b string) *TextDiff

DiffText performs a token-based diff between a and b, returning a TextDiff whose Changes contain merged "equals", "added", and "removed" runs.

func (*TextDiff) HTML

func (td *TextDiff) HTML() template.HTML

Jump to

Keyboard shortcuts

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