Documentation ¶
Index ¶
- Variables
- func Map(dst, src interface{}, opts ...func(*Config)) error
- func MapWithOverwrite(dst, src interface{}, opts ...func(*Config)) error
- func Merge(dst, src interface{}, opts ...func(*Config)) error
- func MergeWithOverwrite(dst, src interface{}, opts ...func(*Config)) error
- func WithAppendSlice(config *Config)
- func WithOverride(config *Config)
- func WithOverrideEmptySlice(config *Config)
- func WithOverwriteWithEmptyValue(config *Config)
- func WithSliceDeepCopy(config *Config)
- func WithTransformers(transformers Transformers) func(*Config)
- func WithTypeCheck(config *Config)
- func WithoutDereference(config *Config)
- type Config
- type Transformers
Constants ¶
This section is empty.
Variables ¶
var ( ErrNilArguments = errors.New("src and dst must not be nil") ErrDifferentArgumentsTypes = errors.New("src and dst must be of same type") ErrNotSupported = errors.New("only structs, maps, and slices are supported") ErrExpectedMapAsDestination = errors.New("dst was expected to be a map") ErrExpectedStructAsDestination = errors.New("dst was expected to be a struct") ErrNonPointerArgument = errors.New("dst must be a pointer") )
Errors reported by Mergo when it finds invalid arguments.
Functions ¶
func Map ¶
Map sets fields' values in dst from src. src can be a map with string keys or a struct. dst must be the opposite: if src is a map, dst must be a valid pointer to struct. If src is a struct, dst must be map[string]interface{}. It won't merge unexported (private) fields and will do recursively any exported field. If dst is a map, keys will be src fields' names in lower camel case. Missing key in src that doesn't match a field in dst will be skipped. This doesn't apply if dst is a map. This is separated method from Merge because it is cleaner and it keeps sane semantics: merging equal types, mapping different (restricted) types.
func MapWithOverwrite ¶
MapWithOverwrite will do the same as Map except that non-empty dst attributes will be overridden by non-empty src attribute values. Deprecated: Use Map(…) with WithOverride
func Merge ¶
Merge will fill any empty for value type attributes on the dst struct using corresponding src attributes if they themselves are not empty. dst and src must be valid same-type structs and dst must be a pointer to struct. It won't merge unexported (private) fields and will do recursively any exported field.
func MergeWithOverwrite ¶
MergeWithOverwrite will do the same as Merge except that non-empty dst attributes will be overridden by non-empty src attribute values. Deprecated: use Merge(…) with WithOverride
func WithAppendSlice ¶
func WithAppendSlice(config *Config)
WithAppendSlice will make merge append slices instead of overwriting it.
func WithOverride ¶
func WithOverride(config *Config)
WithOverride will make merge override non-empty dst attributes with non-empty src attributes values.
func WithOverrideEmptySlice ¶
func WithOverrideEmptySlice(config *Config)
WithOverrideEmptySlice will make merge override empty dst slice with empty src slice.
func WithOverwriteWithEmptyValue ¶
func WithOverwriteWithEmptyValue(config *Config)
WithOverwriteWithEmptyValue will make merge override non empty dst attributes with empty src attributes values.
func WithSliceDeepCopy ¶
func WithSliceDeepCopy(config *Config)
WithSliceDeepCopy will merge slice element one by one with Overwrite flag.
func WithTransformers ¶
func WithTransformers(transformers Transformers) func(*Config)
WithTransformers adds transformers to merge, allowing to customize the merging of some types.
func WithTypeCheck ¶
func WithTypeCheck(config *Config)
WithTypeCheck will make merge check types while overwriting it (must be used with WithOverride).
func WithoutDereference ¶
func WithoutDereference(config *Config)
WithoutDereference prevents dereferencing pointers when evaluating whether they are empty (i.e. a non-nil pointer is never considered empty).