Documentation ¶
Overview ¶
Package automapper provides support for mapping between two different types with compatible fields. The intended application for this is when you use one set of types to represent DTOs (data transfer objects, e.g. json data), and a different set of types internally in the application. Using this package can help converting from one type to another.
This package uses reflection to perform mapping which should be fine for all but the most demanding applications.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Map ¶
func Map(source, dest interface{})
Map fills out the fields in dest with values from source. All fields in the destination object must exist in the source object.
Object hierarchies with nested structs and slices are supported, as long as type types of nested structs/slices follow the same rules, i.e. all fields in destination structs must be found on the source struct.
Embedded/anonymous structs are supported
Values that are not exported/not public will not be mapped.
It is a design decision to panic when a field cannot be mapped in the destination to ensure that a renamed field in either the source or destination does not result in subtle silent bug.
func MapLoose ¶
func MapLoose(source, dest interface{})
MapLoose works just like Map, except it doesn't fail when the destination type contains fields not supplied by the source.
This function is meant to be a temporary solution - the general idea is that the Map function should take a number of options that can modify its behavior - but I'd rather not add that functionality before I have a better idea what is a good options format.
Types ¶
This section is empty.