Documentation
¶
Index ¶
- Constants
- type Change
- type ChangeLog
- func (l *ChangeLog) Add(change *Change)
- func (l *ChangeLog) AddCreate(path *Path, value interface{})
- func (l *ChangeLog) AddDelete(path *Path, value interface{})
- func (l *ChangeLog) AddError(path *Path, err error)
- func (l *ChangeLog) AddUpdate(path *Path, from, to interface{})
- func (l *ChangeLog) Size() int
- func (l *ChangeLog) String() string
- func (l *ChangeLog) ToChangeRecords(source, id, userID string) []*ChangeRecord
- type ChangeRecord
- type ChangeType
- type Comparator
- type Config
- type ConfigOption
- type Differ
- type Option
- type Options
- type Path
- type PathKind
- type Registry
- type Tag
Examples ¶
Constants ¶
View Source
const ( //ChangeTypeCreate defines create change type ChangeTypeCreate = ChangeType("create") //ChangeTypeUpdate defines update change type ChangeTypeUpdate = ChangeType("update") //ChangeTypeDelete defines delete change type ChangeTypeDelete = ChangeType("delete") )
View Source
const ( //PathKindRoot defines root path kind PathKindRoot = PathKind(iota) //PathKinField defines field path kind PathKinField //PathKindKey defines key path kind PathKindKey //PathKindIndex defines index path kind PathKindIndex )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change struct {
Type ChangeType
Path *Path
From interface{}
To interface{}
Error string `json:",omitempty"`
}
Change represents a change
type ChangeLog ¶
type ChangeLog struct {
Changes []*Change
}
ChangeLog represents a change log
func (*ChangeLog) ToChangeRecords ¶
func (l *ChangeLog) ToChangeRecords(source, id, userID string) []*ChangeRecord
ToChangeRecords converts changeLog to change records
type ChangeRecord ¶
type ChangeRecord struct {
Source string `json:",omitempty"`
SourceID string `json:",omitempty"`
UserID string `json:",omitempty"`
Path string
Change string
From interface{} `json:",omitempty"`
To interface{} `json:",omitempty"`
Error string `json:",omitempty"`
}
ChangeRecord defines a change record
type Comparator ¶
Comparator an interface for comparison customization
type Config ¶
type Config struct {
TimeLayout string
NullifyEmpty *bool
TagName string //diff by default
StrictMode bool //non-strict mode allows string with non-string matches
// contains filtered or unexported fields
}
Config represents a config
type ConfigOption ¶ added in v0.3.0
type ConfigOption func(config *Config)
ConfigOption represents an option
func WithRegistry ¶
func WithRegistry(registry *Registry) ConfigOption
WithRegistry updated config with registry
type Differ ¶
type Differ struct {
// contains filtered or unexported fields
}
Differ represents a differ
func New ¶
func New(from, to reflect.Type, opts ...ConfigOption) (*Differ, error)
New creates a differ
Example ¶
ExampleNew shows basic differ usage
package main
import (
"fmt"
"github.com/viant/godiff"
"log"
"reflect"
)
func main() {
type Flag struct {
Value int
}
type Record struct {
Id int
Name string
Dep *Record
Transient string `diff:"-"`
Flags []Flag
}
record1 := &Record{
Id: 1,
Name: "Rec1",
Flags: []Flag{{Value: 3}, {Value: 15}},
}
record2 := &Record{
Id: 2,
Name: "Rec1",
Dep: &Record{Id: 10},
Flags: []Flag{{Value: 12}},
}
diff, err := godiff.New(reflect.TypeOf(record1), reflect.TypeOf(record2))
if err != nil {
log.Fatal(err)
}
changeLog := diff.Diff(record1, record2)
fmt.Println(changeLog.String())
}
type Option ¶
type Option func(c *Options)
func WithSetMarker ¶ added in v0.4.1
func WithShallow ¶ added in v0.3.0
type Path ¶
type Path struct {
Kind PathKind `json:",omitempty"`
Path *Path `json:",omitempty"`
Name string `json:",omitempty"`
Index int `json:",omitempty"`
Key interface{} `json:",omitempty"`
}
Path represents an arbitrary data structure path
Click to show internal directories.
Click to hide internal directories.