Documentation
¶
Index ¶
- func Copy[T any](src T) (T, error)
- func CopySkipUnsupported[T any](src T) (T, error)
- func MustCopy[T any](src T) T
- func Register[T any]()
- type AndCondition
- type Builder
- type CompareCondition
- type Condition
- func And[T any](conds ...Condition[T]) Condition[T]
- func Equal[T any](path string, val any) Condition[T]
- func Greater[T any](path string, val any) Condition[T]
- func GreaterEqual[T any](path string, val any) Condition[T]
- func Less[T any](path string, val any) Condition[T]
- func LessEqual[T any](path string, val any) Condition[T]
- func Not[T any](c Condition[T]) Condition[T]
- func NotEqual[T any](path string, val any) Condition[T]
- func Or[T any](conds ...Condition[T]) Condition[T]
- func ParseCondition[T any](expr string) (Condition[T], error)
- type Copier
- type EqualCondition
- type Node
- func (n *Node) Add(i int, val any) error
- func (n *Node) AddMapEntry(key, val any) error
- func (n *Node) Delete(keyOrIndex any, oldVal any) error
- func (n *Node) Elem() *Node
- func (n *Node) Field(name string) (*Node, error)
- func (n *Node) Index(i int) (*Node, error)
- func (n *Node) MapKey(key any) (*Node, error)
- func (n *Node) Set(old, new any) error
- type NotCondition
- type NotEqualCondition
- type OrCondition
- type Patch
- type Path
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Copy ¶
Copy creates a deep copy of src. It returns the copy and a nil error in case of success and the zero value for the type and a non-nil error on failure.
func CopySkipUnsupported ¶
CopySkipUnsupported creates a deep copy of src. It returns the copy and a nil error in case of success and the zero value for the type and a non-nil error on failure. Unsupported types are skipped (the copy will have the zero value for the type) instead of returning an error.
Types ¶
type AndCondition ¶ added in v1.3.0
func (AndCondition[T]) Evaluate ¶ added in v1.3.0
func (c AndCondition[T]) Evaluate(v *T) (bool, error)
type Builder ¶ added in v1.3.0
type Builder[T any] struct { // contains filtered or unexported fields }
Builder allows constructing a Patch[T] manually with on-the-fly type validation.
func NewBuilder ¶ added in v1.3.0
NewBuilder returns a new Builder for type T.
type CompareCondition ¶ added in v1.3.0
func (CompareCondition[T]) Evaluate ¶ added in v1.3.0
func (c CompareCondition[T]) Evaluate(v *T) (bool, error)
type Copier ¶ added in v1.3.0
Copier is an interface that types can implement to provide their own custom deep copy logic. The type T in Copy() (T, error) must be the same concrete type as the receiver that implements this interface.
type EqualCondition ¶ added in v1.3.0
func (EqualCondition[T]) Evaluate ¶ added in v1.3.0
func (c EqualCondition[T]) Evaluate(v *T) (bool, error)
type Node ¶ added in v1.3.0
type Node struct {
// contains filtered or unexported fields
}
Node represents a specific location within a value's structure.
func (*Node) AddMapEntry ¶ added in v1.3.0
AddMapEntry adds a new entry to a map node.
func (*Node) Elem ¶ added in v1.3.0
Elem returns a Node for the element type of a pointer or interface.
func (*Node) Field ¶ added in v1.3.0
Field returns a Node for the specified struct field. It automatically descends into pointers and interfaces if necessary.
type NotCondition ¶ added in v1.3.0
func (NotCondition[T]) Evaluate ¶ added in v1.3.0
func (c NotCondition[T]) Evaluate(v *T) (bool, error)
type NotEqualCondition ¶ added in v1.3.0
func (NotEqualCondition[T]) Evaluate ¶ added in v1.3.0
func (c NotEqualCondition[T]) Evaluate(v *T) (bool, error)
type OrCondition ¶ added in v1.3.0
func (OrCondition[T]) Evaluate ¶ added in v1.3.0
func (c OrCondition[T]) Evaluate(v *T) (bool, error)
type Patch ¶ added in v1.3.0
type Patch[T any] interface { fmt.Stringer // Apply applies the patch to the value pointed to by v. // The value v must not be nil. Apply(v *T) // ApplyChecked applies the patch only if specific conditions are met. // 1. If the patch has a global Condition, it must evaluate to true. // 2. For every modification, the target value must match the 'oldVal' recorded in the patch. ApplyChecked(v *T) error // WithCondition returns a new Patch with the given condition attached. WithCondition(c Condition[T]) Patch[T] // Reverse returns a new Patch that undoes the changes in this patch. Reverse() Patch[T] }
Patch represents a set of changes that can be applied to a value of type T.
func Diff ¶ added in v1.3.0
Diff compares two values a and b and returns a Patch that can be applied to a to make it equal to b.
It uses a combination of Myers' Diff algorithm for slices and recursive type-specific comparison for structs, maps, and pointers.
If a and b are deeply equal, it returns nil.