gomerge

package module
v0.0.0-...-5609fe8 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

README

gomerge

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Merge

func Merge(dst, src interface{}, opts ...func(*Options)) error

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

func WithoutOverwrite

func WithoutOverwrite(o *Options)

WithoutOverwrite ...

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"
)

Jump to

Keyboard shortcuts

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