differ

package
v0.0.0-...-dec35dd Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

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
}

Change represents a change

type ChangeLog

type ChangeLog struct {
	Changes []*Change
}

ChangeLog represents a change log

func (*ChangeLog) ToChangeRecords

func (l *ChangeLog) ToChangeRecords(options ...LogOption) []*ChangeRecord

ToChangeRecords converts changeLog to change records

type ChangeRecord

type ChangeRecord struct {
	Source   string      `json:",omitempty"`
	SourceID interface{} `json:",omitempty"`
	UserID   interface{} `json:",omitempty"`
	Path     string
	Change   string
	From     interface{} `json:",omitempty"`
	To       interface{} `json:",omitempty"`
	Error    string      `json:",omitempty"`
}

ChangeRecord defines a change record

type ChangeType

type ChangeType string

ChangeType defines a change type

type Differ

type Differ interface {
	Diff(ctx context.Context, from, to interface{}, options ...Option) *ChangeLog
}

type LogOption

type LogOption func(l *logOptions)

func WithSource

func WithSource(source string) LogOption

func WithSourceID

func WithSourceID(id interface{}) LogOption

func WithUserID

func WithUserID(userID interface{}) LogOption

type Option

type Option func(o *Options)

Option defines validator option

func WithSetMarker

func WithSetMarker(f bool) Option

WithSetMarker creates with shallow option

func WithShallow

func WithShallow(f bool) Option

WithShallow creates with shallow option

type Options

type Options struct {
	WithShallow   bool
	WithSetMarker bool
}

Options defins validator options

func (*Options) Apply

func (o *Options) Apply(opts ...Option)

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

func (*Path) Element

func (p *Path) Element(index int) *Path

Element adds slice element node

func (*Path) Entry

func (p *Path) Entry(name string) *Path

Entry adds map entry node

func (*Path) Field

func (p *Path) Field(name string) *Path

Field add fields node

func (*Path) String

func (p *Path) String() string

String stringifies a path

type PathKind

type PathKind int

PathKind defines patch kind

type Service

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

func New

func New(differ Differ) *Service

func (*Service) Diff

func (s *Service) Diff(ctx context.Context, from, to interface{}, options ...Option) *ChangeLog

Jump to

Keyboard shortcuts

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