Documentation
¶
Index ¶
- func AsMerger(value reflect.Value) (mergeFn func(override reflect.Value) (reflect.Value, error), isMerger bool)
- func Merge[T any](src T, patch T, opts ...Option) (T, error)
- type AtomicTypes
- type CustomMergeFunc
- type CustomMergeFuncs
- type CustomMergeOptions
- type MergeOptionsProvider
- type Merger
- type Option
- func OptAtomicTypes(atomicTypes AtomicTypes) Option
- func OptCustomMergeFuncs(customMergeFuncs CustomMergeFuncs) Option
- func OptCustomMergeOptions(customMergeOptions CustomMergeOptions) Option
- func OptDeRefPointers(deRefPointers bool) Option
- func OptIterateMaps(iterateMaps bool) Option
- func OptMergeSlices(iterateSlices SlicesMergeStrategy) Option
- func OptRespectMergeOptionsProviders(respectMergeOptionsProviders bool) Option
- func OptRespectMergers(respectMergers bool) Option
- type Options
- type SlicesMergeStrategy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AtomicTypes ¶
type CustomMergeFunc ¶
type CustomMergeFuncs ¶
CustomMergeFuncs is a map of types to custom merge functions. Values should be of CustomMergeFunc[T] type where T is the same type as the key points to.
type CustomMergeOptions ¶
type MergeOptionsProvider ¶
type MergeOptionsProvider interface {
GetMergeOptions() Options
}
type Option ¶
type Option func(*Options)
func OptAtomicTypes ¶
func OptAtomicTypes(atomicTypes AtomicTypes) Option
OptAtomicTypes sets Options.AtomicTypes
func OptCustomMergeFuncs ¶
func OptCustomMergeFuncs(customMergeFuncs CustomMergeFuncs) Option
OptCustomMergeFuncs sets Options.CustomMergeFuncs
func OptCustomMergeOptions ¶
func OptCustomMergeOptions(customMergeOptions CustomMergeOptions) Option
OptCustomMergeOptions sets Options.CustomMergeOptions
func OptDeRefPointers ¶
OptDeRefPointers Sets Options.DeRefPointers
func OptIterateMaps ¶
OptIterateMaps sets Options.IterateMaps
func OptMergeSlices ¶
func OptMergeSlices(iterateSlices SlicesMergeStrategy) Option
OptMergeSlices sets Options.SlicesMerge
func OptRespectMergeOptionsProviders ¶
OptRespectMergeOptionsProviders sets Options.RespectMergeOptionsProviders
func OptRespectMergers ¶
OptRespectMergers sets Options.RespectMergers
type Options ¶
type Options struct {
// RespectMergers sets whether to respect Merger interface for fields. If true, fields that implement
// Merger will be merged using their Merge method.
// Default: true
// Use OptRespectMergers to set this option
RespectMergers bool
// CustomMergeFuncs sets custom merge functions for specific types. If merge function is set for a type,
// it will be used instead of default merge logic.
// See CustomMergeFuncs for more details about functions signature.
// Use OptCustomMergeFuncs to set this option
CustomMergeFuncs CustomMergeFuncs
// RespectMergeOptionsProviders sets whether to respect MergeOptionsProvider interface for fields. If true,
// fields that implement MergeOptionsProvider will be merged with options returned from their GetMergeOptions method.
// If CustomMergeOptions is set for a type, it will be used instead.
// Default: true
// Use OptRespectMergeOptionsProviders to set this option
RespectMergeOptionsProviders bool
// CustomMergeOptions sets custom merge options for specific types. If merge options are set for a type,
// they will be used instead of merge options passed to Merge function.
// Use OptCustomMergeOptions to set this option
CustomMergeOptions CustomMergeOptions
// DeRefPointers sets comparison mode for fields containing pointers (only if they are not Merger or
// have defined custom merge function)
// - If true, pointers will be de-referenced (if not nil) and their values will be compared.
// if `patch` pointer is nil, `src` pointer will be used.
// - If false, pointers will be compared directly.
//
// Default: true
// Use OptDeRefPointers to set this option
DeRefPointers bool
// sets types that should be treated as atomic. For a struct it means fields will not be iterated
// and two structs will be compared with reflect.DeepEqual. If they are not equal, patch value will be used.
// Use OptAtomicTypes to set this option
AtomicTypes AtomicTypes
// IterateMaps sets whether to iterate maps considering their keys as individual values.
// If true, maps will be iterated and merged by keys (calling merge func with options recursively for values).
// If false, maps will be compared with reflect.DeepEqual and patch value will be used if they are not equal.
// Default: false
// Use OptIterateMaps to set this option
IterateMaps bool
// MergeSlices sets how to merge slices.
// See SlicesMergeStrategy for more details.
// Default: SlicesMergeStrategyAtomic
// Use OptMergeSlices to set this option
SlicesMerge SlicesMergeStrategy
// contains filtered or unexported fields
}
func NewOptions ¶
type SlicesMergeStrategy ¶
type SlicesMergeStrategy string
SlicesMergeStrategy defines how to merge slices
const ( // SlicesMergeStrategyAtomic considers slices as atomic values. Patch will entirely replace src if patch is not nil. SlicesMergeStrategyAtomic SlicesMergeStrategy = "atomic" // SlicesMergeStrategyUnique considers slices as sets of unique elements. // Patch element will be appended to src slice if it's not present in src. // If slice contains not comparable elements, it roll backs SlicesMergeStrategyAtomic SlicesMergeStrategyUnique SlicesMergeStrategy = "unique" // SlicesMergeStrategyByIndex merges elements with the same indexes. // Patch slice elements will replace the src element if the patch slice element is not a zero value // If patch slice is longer than src slice, remaining patch slice elements will be appended to src slice SlicesMergeStrategyByIndex SlicesMergeStrategy = "by_index" )
Source Files
¶
Click to show internal directories.
Click to hide internal directories.