automapper

package module
v0.0.0-...-7c63d5b Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2020 License: MIT Imports: 2 Imported by: 6

README

go-automapper

GoDoc

Go-automapper can automatically map data between different types with identically named fields in GO. Useful for initializing DTO types from build in data.

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.

Jump to

Keyboard shortcuts

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