diff

package module
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 License: MPL-2.0 Imports: 9 Imported by: 50

README

Diff PkgGoDev Go Report Card Build Status

A library for diffing golang structures and values.

Utilizing field tags and reflection, it is able to compare two structures of the same type and create a changelog of all modified values. The produced changelog can easily be serialized to json.

NOTE: All active development now takes place on the v3 branch.

Installation

For version 3:

go get github.com/r3labs/diff/v3

Changelog Format

When diffing two structures using Diff, a changelog will be produced. Any detected changes will populate the changelog array with a Change type:

type Change struct {
	Type string      // The type of change detected; can be one of create, update or delete
	Path []string    // The path of the detected change; will contain any field name or array index that was part of the traversal
	From interface{} // The original value that was present in the "from" structure
	To   interface{} // The new value that was detected as a change in the "to" structure
}

Given the example below, we are diffing two slices where the third element has been removed:

from := []int{1, 2, 3, 4}
to := []int{1, 2, 4}

changelog, _ := diff.Diff(from, to)

The resultant changelog should contain one change:

Change{
    Type: "delete",
    Path: ["2"],
    From: 3,
    To:   nil,
}

Supported Types

A diffable value can be/contain any of the following types:

Type Supported
struct
slice
string
int
bool
map
pointer
custom types

Please see the docs for more supported types, options and features.

Tags

In order for struct fields to be compared, they must be tagged with a given name. All tag values are prefixed with diff. i.e. diff:"items".

Tag Usage
- Excludes a value from being diffed
identifier If you need to compare arrays by a matching identifier and not based on order, you can specify the identifier tag. If an identifiable element is found in both the from and to structures, they will be directly compared. i.e. diff:"name, identifier"
immutable Will omit this struct field from diffing. When using diff.StructValues() these values will be added to the returned changelog. It's use case is for when we have nothing to compare a struct to and want to show all of its relevant values.
nocreate The default patch action is to allocate instances in the target strut, map or slice should they not exist. Adding this flag will tell patch to skip elements that it would otherwise need to allocate. This is separate from immutable, which is also honored while patching.
omitunequal Patching is a 'best effort' operation, and will by default attempt to update the 'correct' member of the target even if the underlying value has already changed to something other than the value in the change log 'from'. This tag will selectively ignore values that are not a 100% match.

Usage

Basic Example

Diffing a basic set of values can be accomplished using the diff functions. Any items that specify a "diff" tag using a name will be compared.

import "github.com/r3labs/diff/v3"

type Order struct {
    ID    string `diff:"id"`
    Items []int  `diff:"items"`
}

func main() {
    a := Order{
        ID: "1234",
        Items: []int{1, 2, 3, 4},
    }

    b := Order{
        ID: "1234",
        Items: []int{1, 2, 4},
    }

    changelog, err := diff.Diff(a, b)
    ...
}

In this example, the output generated in the changelog will indicate that the third element with a value of '3' was removed from items. When marshalling the changelog to json, the output will look like:

[
    {
        "type": "delete",
        "path": ["items", "2"],
        "from": 3,
        "to": null
    }
]
Options and Configuration

Options can be set on the differ at call time which effect how diff acts when building the change log.

import "github.com/r3labs/diff/v3"

type Order struct {
    ID    string `diff:"id"`
    Items []int  `diff:"items"`
}

func main() {
    a := Order{
        ID: "1234",
        Items: []int{1, 2, 3, 4},
    }

    b := Order{
        ID: "1234",
        Items: []int{1, 2, 4},
    }

    changelog, err := diff.Diff(a, b, diff.DisableStructValues(), diff.AllowTypeMismatch(true))
    ...
}

You can also create a new instance of a differ that allows options to be set.

import "github.com/r3labs/diff/v3"

type Order struct {
    ID    string `diff:"id"`
    Items []int  `diff:"items"`
}

func main() {
    a := Order{
        ID: "1234",
        Items: []int{1, 2, 3, 4},
    }

    b := Order{
        ID: "1234",
        Items: []int{1, 2, 4},
    }

    d, err := diff.NewDiffer(diff.SliceOrdering(true))
    if err != nil {
        panic(err)
    }

    changelog, err := d.Diff(a, b)
    ...
}

Supported options are:

SliceOrdering ensures that the ordering of items in a slice is taken into account

DiscardComplexOrigin is a directive to diff to omit additional origin information about structs. This alters the behavior of patch and can lead to some pitfalls and non-intuitive behavior if used. On the other hand, it can significantly reduce the memory footprint of large complex diffs.

AllowTypeMismatch is a global directive to either allow (true) or not to allow (false) patch apply the changes if 'from' is not equal. This is effectively a global version of the omitunequal tag.

Filter provides a callback that allows you to determine which fields the differ descends into

DisableStructValues disables populating a separate change for each item in a struct, where the struct is being compared to a nil Value.

TagName sets the tag name to use when getting field names and options.

Patch and merge support

Diff additionally supports merge and patch. Similar in concept to text patching / merging the Patch function, given a change log and a target instance will make a best effort to apply the changes in the change log to the variable pointed to. The intention is that the target pointer is of the same type however, that doesn't necessarily have to be true. For example, two slices of differing structs may be similar enough to apply changes to in a polymorphic way, and patch will certainly try.

The patch function doesn't actually fail, and even if there are errors, it may succeed sufficiently for the task at hand. To accommodate this patch keeps track of each change log option it attempts to apply and reports the details of what happened for further scrutiny.

import "github.com/r3labs/diff/v3"

type Order struct {
    ID    string `diff:"id"`
    Items []int  `diff:"items"`
}

func main() {
    a := Order{
        ID: "1234",
        Items: []int{1, 2, 3, 4},
    }

    b := Order{
        ID: "1234",
        Items: []int{1, 2, 4},
    }

    c := Order{}
    changelog, err := diff.Diff(a, b)

    patchlog := diff.Patch(changelog, &c)
    //Note the lack of an error. Patch is best effort and uses flags to indicate actions taken
    //and keeps any errors encountered along the way for review
    fmt.Printf("Encountered %d errors while patching", patchlog.ErrorCount())
    ...
}

Instances of differ with options set can also be used when patching.

package main

import "github.com/r3labs/diff/v3"

type Order struct {
	ID    string `json:"id"`
	Items []int  `json:"items"`
}

func main() {
    a := Order{
        ID:    "1234",
        Items: []int{1, 2, 3, 4},
        }

    b := Order{
        ID:    "1234",
        Items: []int{1, 2, 4},
    }

    d, _ := diff.NewDiffer(diff.TagName("json"))

    changelog, _ := d.Diff(a, b)

    d.Patch(changelog, &a)
    // reflect.DeepEqual(a, b) == true
}

As a convenience, there is a Merge function that allows one to take three interfaces and perform all the tasks at the same time.

import "github.com/r3labs/diff/v3"

type Order struct {
    ID    string `diff:"id"`
    Items []int  `diff:"items"`
}

func main() {
    a := Order{
        ID: "1234",
        Items: []int{1, 2, 3, 4},
    }

    b := Order{
        ID: "1234",
        Items: []int{1, 2, 4},
    }

    c := Order{}
    patchlog, err := diff.Merge(a, b, &c)
    if err != nil {
        fmt.Printf("Error encountered while diffing a & b")
    }
    fmt.Printf("Encountered %d errors while patching", patchlog.ErrorCount())
    ...
}

Running Tests

make test

Contributing

Please read through our contributing guidelines. Included are directions for opening issues, coding standards, and notes on development.

Moreover, if your pull request contains patches or features, you must include relevant unit tests.

Versioning

For transparency into our release cycle and in striving to maintain backward compatibility, this project is maintained under the Semantic Versioning guidelines.

Code and documentation copyright since 2015 r3labs.io authors.

Code released under the Mozilla Public License Version 2.0.

Documentation

Index

Examples

Constants

View Source
const (
	// CREATE represents when an element has been added
	CREATE = "create"
	// UPDATE represents when an element has been updated
	UPDATE = "update"
	// DELETE represents when an element has been removed
	DELETE = "delete"
)

Variables

View Source
var (
	// ErrTypeMismatch Compared types do not match
	ErrTypeMismatch = NewError("types do not match")
	// ErrInvalidChangeType The specified change values are not unsupported
	ErrInvalidChangeType = NewError("change type must be one of 'create' or 'delete'")
)

Functions

func AllowTypeMismatch

func AllowTypeMismatch(enabled bool) func(d *Differ) error

AllowTypeMismatch changed behaviour to report value as "updated" when its type has changed instead of error

func AreType

func AreType(a, b reflect.Value, types ...reflect.Type) bool

func Changed

func Changed(a, b interface{}) bool

Changed returns true if both values differ

func ConvertCompatibleTypes

func ConvertCompatibleTypes() func(d *Differ) error

ConvertTypes enables values that are convertible to the target type to be converted when patching

func CustomValueDiffers

func CustomValueDiffers(vd ...ValueDiffer) func(d *Differ) error

CustomValueDiffers allows you to register custom differs for specific types

func DisableStructValues

func DisableStructValues() func(d *Differ) error

DisableStructValues disables populating a separate change for each item in a struct, where the struct is being compared to a nil value

func DiscardComplexOrigin

func DiscardComplexOrigin() func(d *Differ) error

DiscardComplexOrigin - by default, we are now keeping the complex struct associated with a create entry. This allows us to fix the merge to new object issue of not having enough change log details when allocating new objects. This however is a trade off of memory size and complexity vs correctness which is often only necessary when embedding structs in slices and arrays. It memory constrained environments, it may be desirable to turn this feature off however from a computational perspective, keeping the complex origin is actually quite cheap so, make sure you're extremely clear on the pitfalls of turning this off prior to doing so.

func Filter

func Filter(f FilterFunc) func(d *Differ) error

Filter allows you to determine which fields the differ descends into

Example
type Tag struct {
	Name  string `diff:"name,identifier"`
	Value string `diff:"value"`
}

type Fruit struct {
	ID        int      `diff:"id"`
	Name      string   `diff:"name"`
	Healthy   bool     `diff:"healthy"`
	Nutrients []string `diff:"nutrients"`
	Tags      []Tag    `diff:"tags"`
}

a := Fruit{
	ID:      1,
	Name:    "Green Apple",
	Healthy: true,
	Nutrients: []string{
		"vitamin c",
		"vitamin d",
	},
}

b := Fruit{
	ID:      2,
	Name:    "Red Apple",
	Healthy: true,
	Nutrients: []string{
		"vitamin c",
		"vitamin d",
		"vitamin e",
	},
}

d, err := diff.NewDiffer(diff.Filter(func(path []string, parent reflect.Type, field reflect.StructField) bool {
	return field.Name != "Name"
}))
if err != nil {
	panic(err)
}

changelog, err := d.Diff(a, b)
if err != nil {
	panic(err)
}

fmt.Printf("%#v", changelog)
Output:

diff.Changelog{diff.Change{Type:"update", Path:[]string{"id"}, From:1, To:2, parent:diff_test.Fruit{ID:1, Name:"Green Apple", Healthy:true, Nutrients:[]string{"vitamin c", "vitamin d"}, Tags:[]diff_test.Tag(nil)}}, diff.Change{Type:"create", Path:[]string{"nutrients", "2"}, From:interface {}(nil), To:"vitamin e", parent:interface {}(nil)}}

func FlattenEmbeddedStructs

func FlattenEmbeddedStructs() func(d *Differ) error

FlattenEmbeddedStructs determines whether fields of embedded structs should behave as if they are directly under the parent

func SliceOrdering

func SliceOrdering(enabled bool) func(d *Differ) error

SliceOrdering determines whether the ordering of items in a slice results in a change

func StructMapKeySupport

func StructMapKeySupport() func(d *Differ) error

StructMapKeySupport - Changelog paths do not provided structured object values for maps that contain complex keys (such as other structs). You must enable this support via an option and it then uses msgpack to encode path elements that are structs. If you don't have this on, and try to patch, your apply will fail for that element.

func TagName

func TagName(tag string) func(d *Differ) error

TagName sets the tag name to use when getting field names and options

Types

type Change

type Change struct {
	Type string      `json:"type"`
	Path []string    `json:"path"`
	From interface{} `json:"from"`
	To   interface{} `json:"to"`
	// contains filtered or unexported fields
}

Change stores information about a changed item

type ChangeValue

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

ChangeValue is a specialized struct for monitoring patching

func NewChangeValue

func NewChangeValue(d *Differ, c Change, target interface{}) (ret *ChangeValue)

NewChangeValue idiomatic constructor (also invokes render)

func (*ChangeValue) AddError

func (c *ChangeValue) AddError(err error) *ChangeValue

AddError appends errors to this change value

func (*ChangeValue) ClearFlag

func (c *ChangeValue) ClearFlag(flag PatchFlags)

ClearFlag removes just a single flag

func (*ChangeValue) HasFlag

func (c *ChangeValue) HasFlag(flag PatchFlags) bool

HasFlag indicates if a flag is set on the node. returns false if node is bad

func (ChangeValue) Index

func (c ChangeValue) Index(i int) reflect.Value

Index echo for index

func (*ChangeValue) IsValid

func (c *ChangeValue) IsValid() bool

IsValid echo for is valid

func (ChangeValue) Len

func (c ChangeValue) Len() int

Len echo for len

func (ChangeValue) NewArrayElement

func (c ChangeValue) NewArrayElement() reflect.Value

NewArrayElement gives us a dynamically typed new element

func (ChangeValue) NewElement

func (c ChangeValue) NewElement() reflect.Value

Instance a new element of type for target. Taking the copy of the complex origin avoids the 'lack of data' issue present when allocating complex structs with slices and arrays

func (ChangeValue) ParentIndex

func (c ChangeValue) ParentIndex(i int) (ret reflect.Value)

ParentIndex - get us the parent version, nil safe

func (ChangeValue) ParentKind

func (c ChangeValue) ParentKind() reflect.Kind

ParentKind - helps keep us nil safe

func (ChangeValue) ParentLen

func (c ChangeValue) ParentLen() (ret int)

ParentLen is a nil safe parent length check

func (*ChangeValue) ParentSet

func (c *ChangeValue) ParentSet(value reflect.Value, convertCompatibleTypes bool)

ParentSet - nil safe parent set

func (*ChangeValue) Set

func (c *ChangeValue) Set(value reflect.Value, convertCompatibleTypes bool)

Set echos reflect set

func (*ChangeValue) SetFlag

func (c *ChangeValue) SetFlag(flag PatchFlags)

Sets a flag on the node and saves the change

type Changelog

type Changelog []Change

Changelog stores a list of changed items

func Diff

func Diff(a, b interface{}, opts ...func(d *Differ) error) (Changelog, error)

Diff returns a changelog of all mutated values from both

Example
type Tag struct {
	Name  string `diff:"name,identifier"`
	Value string `diff:"value"`
}

type Fruit struct {
	ID        int      `diff:"id"`
	Name      string   `diff:"name"`
	Healthy   bool     `diff:"healthy"`
	Nutrients []string `diff:"nutrients"`
	Tags      []Tag    `diff:"tags"`
}

a := Fruit{
	ID:      1,
	Name:    "Green Apple",
	Healthy: true,
	Nutrients: []string{
		"vitamin c",
		"vitamin d",
	},
	Tags: []Tag{
		{
			Name:  "kind",
			Value: "fruit",
		},
	},
}

b := Fruit{
	ID:      2,
	Name:    "Red Apple",
	Healthy: true,
	Nutrients: []string{
		"vitamin c",
		"vitamin d",
		"vitamin e",
	},
	Tags: []Tag{
		{
			Name:  "popularity",
			Value: "high",
		},
		{
			Name:  "kind",
			Value: "fruit",
		},
	},
}

changelog, err := diff.Diff(a, b)
if err != nil {
	panic(err)
}

fmt.Printf("%#v", changelog)
// Produces: diff.Changelog{diff.Change{Type:"update", Path:[]string{"id"}, From:1, To:2}, diff.Change{Type:"update", Path:[]string{"name"}, From:"Green Apple", To:"Red Apple"}, diff.Change{Type:"create", Path:[]string{"nutrients", "2"}, From:interface {}(nil), To:"vitamin e"}, diff.Change{Type:"create", Path:[]string{"tags", "popularity"}, From:interface {}(nil), To:main.Tag{Name:"popularity", Value:"high"}}}
Output:

func StructValues

func StructValues(t string, path []string, s interface{}) (Changelog, error)

StructValues gets all values from a struct values are stored as "created" or "deleted" entries in the changelog, depending on the change type specified

func (*Changelog) Add

func (cl *Changelog) Add(t string, path []string, ftco ...interface{})

func (*Changelog) Filter

func (cl *Changelog) Filter(path []string) Changelog

Filter filter changes based on path. Paths may contain valid regexp to match items

func (*Changelog) FilterOut

func (cl *Changelog) FilterOut(path []string) Changelog

FilterOut filter out the changes based on path. Paths may contain valid regexp to match items

type Comparative

type Comparative struct {
	A, B *reflect.Value
}

Comparative ...

type ComparativeList

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

ComparativeList : stores indexed comparative

func NewComparativeList

func NewComparativeList() *ComparativeList

NewComparativeList : returns a new comparative list

type DiffError

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

our own version of an error, which can wrap others

func NewError

func NewError(message string, causes ...error) *DiffError

NewError just give me a plain error

func NewErrorf

func NewErrorf(format string, messages ...interface{}) *DiffError

NewErrorf just give me a plain error with formatting

func (DiffError) Error

func (s DiffError) Error() string

Error implements the error interface

func (*DiffError) Unwrap

func (s *DiffError) Unwrap() error

Unwrap implement 1.13 unwrap feature for compatibility

func (*DiffError) WithCause

func (s *DiffError) WithCause(err error) *DiffError

AppendCause appends a new cause error to the chain

type DiffFunc

type DiffFunc func([]string, reflect.Value, reflect.Value, interface{}) error

DiffFunc represents the built-in diff functions

type DiffType

type DiffType uint8

DiffType represents an enum with all the supported diff types

const (
	UNSUPPORTED DiffType = iota
	STRUCT
	SLICE
	ARRAY
	STRING
	BOOL
	INT
	UINT
	FLOAT
	MAP
	PTR
	INTERFACE
)

func (DiffType) String

func (t DiffType) String() string

type Differ

type Differ struct {
	TagName             string
	SliceOrdering       bool
	DisableStructValues bool

	AllowTypeMismatch      bool
	DiscardParent          bool
	StructMapKeys          bool
	FlattenEmbeddedStructs bool
	ConvertCompatibleTypes bool
	Filter                 FilterFunc
	// contains filtered or unexported fields
}

Differ a configurable diff instance

func NewDiffer

func NewDiffer(opts ...func(d *Differ) error) (*Differ, error)

NewDiffer creates a new configurable diffing object

func (*Differ) Diff

func (d *Differ) Diff(a, b interface{}) (Changelog, error)

Diff returns a changelog of all mutated values from both

func (*Differ) Merge

func (d *Differ) Merge(original interface{}, changed interface{}, target interface{}) (PatchLog, error)

Merge is a convenience function that diffs, the original and changed items and merges said changes with target all in one call.

func (*Differ) Patch

func (d *Differ) Patch(cl Changelog, target interface{}) (ret PatchLog)

Patch... the missing feature.

type FilterFunc

type FilterFunc func(path []string, parent reflect.Type, field reflect.StructField) bool

FilterFunc is a function that determines whether to descend into a struct field. parent is the struct being examined and field is a field on that struct. path is the path to the field from the root of the diff.

type PatchFlags

type PatchFlags uint32

Not strictly necessary but might be nice in some cases

const (
	OptionCreate PatchFlags = 1 << iota
	OptionNoCreate
	OptionOmitUnequal
	OptionImmutable
	FlagInvalidTarget
	FlagApplied
	FlagFailed
	FlagCreated
	FlagIgnored
	FlagDeleted
	FlagUpdated
	FlagParentSetApplied
	FlagParentSetFailed
)

type PatchLog

type PatchLog []PatchLogEntry

func Merge

func Merge(original interface{}, changed interface{}, target interface{}) (PatchLog, error)
Example

ExampleMerge demonstrates how to use the Merge function

type Fruit struct {
	ID        int            `diff:"ID" json:"Identifier"`
	Name      string         `diff:"name"`
	Healthy   bool           `diff:"healthy"`
	Nutrients []string       `diff:"nutrients,create,omitunequal"`
	Labels    map[string]int `diff:"labs,create"`
}

a := Fruit{
	ID:      1,
	Name:    "Green Apple",
	Healthy: true,
	Nutrients: []string{
		"vitamin a",
		"vitamin b",
		"vitamin c",
		"vitamin d",
	},
	Labels: make(map[string]int),
}
a.Labels["likes"] = 10
a.Labels["colors"] = 2

b := Fruit{
	ID:      2,
	Name:    "Red Apple",
	Healthy: true,
	Nutrients: []string{
		"vitamin c",
		"vitamin d",
		"vitamin e",
	},
	Labels: make(map[string]int),
}
b.Labels["forests"] = 1223
b.Labels["colors"] = 1222

c := Fruit{
	Labels: make(map[string]int),
	Nutrients: []string{
		"vitamin a",
		"vitamin c",
		"vitamin d",
	},
}
c.Labels["likes"] = 21
c.Labels["colors"] = 42

//the only error that can happen here comes from the diff step
patchLog, _ := diff.Merge(a, b, &c)

//Note that unlike our patch version we've not included 'create' in the
//tag for nutrients. This will omit "vitamin e" from ending up in c
fmt.Printf("%#v", len(patchLog))
Output:

8

func Patch

func Patch(cl Changelog, target interface{}) (ret PatchLog)
Example

ExamplePatch demonstrates how to use the Patch function

type Key struct {
	value  string
	weight int
}
type Cycle struct {
	Name  string `diff:"name,create"`
	Count int    `diff:"count,create"`
}
type Fruit struct {
	ID        int           `diff:"ID" json:"Identifier"`
	Name      string        `diff:"name"`
	Healthy   bool          `diff:"healthy"`
	Nutrients []string      `diff:"nutrients,create,omitunequal"`
	Labels    map[Key]Cycle `diff:"labs,create"`
	Cycles    []Cycle       `diff:"cycles,immutable"`
	Weights   []int
}

a := Fruit{
	ID:      1,
	Name:    "Green Apple",
	Healthy: true,
	Nutrients: []string{
		"vitamin a",
		"vitamin b",
		"vitamin c",
		"vitamin d",
	},
	Labels: make(map[Key]Cycle),
}
a.Labels[Key{value: "likes"}] = Cycle{
	Count: 10,
}
a.Labels[Key{value: "colors"}] = Cycle{
	Count: 2,
}

b := Fruit{
	ID:      2,
	Name:    "Red Apple",
	Healthy: true,
	Nutrients: []string{
		"vitamin c",
		"vitamin d",
		"vitamin e",
	},
	Labels: make(map[Key]Cycle),
	Weights: []int{
		1,
		2,
		3,
		4,
	},
}
b.Labels[Key{value: "forests"}] = Cycle{
	Count: 1223,
}
b.Labels[Key{value: "colors"}] = Cycle{
	Count: 1222,
}

c := Fruit{
	//Labels: make(map[string]int),
	Nutrients: []string{
		"vitamin a",
		"vitamin c",
		"vitamin d",
	},
}
//c.Labels["likes"] = 21

d := a
d.Cycles = []Cycle{
	Cycle{
		Name:  "First",
		Count: 45,
	},
	Cycle{
		Name:  "Third",
		Count: 4,
	},
}
d.Nutrients = append(d.Nutrients, "minerals")

changelog, err := diff.Diff(a, b)
if err != nil {
	panic(err)
}

patchLog := diff.Patch(changelog, &c)

changelog, _ = diff.Diff(a, d)
patchLog = diff.Patch(changelog, &c)

fmt.Printf("%#v", len(patchLog))
Output:

1

func (PatchLog) Applied

func (p PatchLog) Applied() bool

Applied - returns true if all change log entries were actually

applied, regardless of if any errors were encountered

func (PatchLog) ErrorCount

func (p PatchLog) ErrorCount() (ret uint)

ErrorCount -- counts the number of errors encountered while patching

func (PatchLog) HasErrors

func (p PatchLog) HasErrors() (ret bool)

HasErrors - indicates if a patch log contains any errors

type PatchLogEntry

type PatchLogEntry struct {
	Path   []string    `json:"path"`
	From   interface{} `json:"from"`
	To     interface{} `json:"to"`
	Flags  PatchFlags  `json:"flags"`
	Errors error       `json:"errors"`
}

PatchLogEntry defines how a DiffLog entry was applied

func NewPatchLogEntry

func NewPatchLogEntry(cv *ChangeValue) PatchLogEntry

NewPatchLogEntry converts our complicated reflection based struct to a simpler format for the consumer

func (PatchLogEntry) HasFlag

func (p PatchLogEntry) HasFlag(flag PatchFlags) bool

HasFlag - convenience function for users

type ValueDiffer

type ValueDiffer interface {
	Match(a, b reflect.Value) bool
	Diff(dt DiffType, df DiffFunc, cl *Changelog, path []string, a, b reflect.Value, parent interface{}) error
	InsertParentDiffer(dfunc func(path []string, a, b reflect.Value, p interface{}) error)
}

ValueDiffer is an interface for custom differs

Jump to

Keyboard shortcuts

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