Documentation
¶
Index ¶
- func Merge(dst, src interface{}, opts ...func(*Options)) error
- func WithConverters(fns ...interface{}) func(*Options)
- func WithMergeFuncs(fns ...interface{}) func(*Options)
- func WithSliceMode(mode SliceMergeMode) func(*Options)
- func WithoutGoConvertion(o *Options)
- func WithoutOverwrite(o *Options)
- type Options
- type SliceMergeMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Merge ¶
Merge the given source onto the given target following the options given. The target value must be a pointer. Merge will accept any two entities, even if their types are diffrent as long as there is convert function (see WithConverters).
func WithConverters ¶
func WithConverters(fns ...interface{}) func(*Options)
WithConverters add custom convert funcs, func sign is like:
func(dst string, src int, o *Options) (string, error) {}
It follows the rules: - the function must have three params - the function must have tow return values - the first param and first return must be the same type - the third param must be *Option - the last return must be error - the first and second params should be different type
func WithMergeFuncs ¶
func WithMergeFuncs(fns ...interface{}) func(*Options)
WithMergeFuncs add custom merge funcs, func sigh is like
func(dst, src int, o *Options) (int, error) {}
It follows the rules: - the function must have three params - the function must have tow return values - the first, second param and first return must be the same type - the third param must be *Option - the last return must be error
func WithSliceMode ¶
func WithSliceMode(mode SliceMergeMode) func(*Options)
WithSliceMode changes slice merge mode
func WithoutGoConvertion ¶
func WithoutGoConvertion(o *Options)
WithoutGoConvertion disables the golang defaultMerge rules
Types ¶
type Options ¶
type Options struct { Overwrite bool GoConvertion bool SliceMode SliceMergeMode AppendSlice bool IntersectSlice bool // contains filtered or unexported fields }
Options ..
type SliceMergeMode ¶
type SliceMergeMode string
SliceMergeMode specify which merge strategy will be applied when merging slice
const ( // ReplaceSlice replaces tow slices ReplaceSlice SliceMergeMode = "Replace" // UniteSlice unite tow slices if the element in slice is hashable. // If the kind of element is not hashable of bool, it will fallthrough to use ApplenSlice // see hashable() to find out what kind is hashable now // // why we don't unite tow bool slices? Imagine that // if we want to unite []bool{true, false, true} and []bool{true} // the resule will be []bool{true, false, true}, it makes no sense. UniteSlice SliceMergeMode = "Unite" // AppendSlice appends all elements of source slice to the target AppendSlice SliceMergeMode = "Append" )