Generation
Here is a broad non exhaustive outline what goverter does. Goverter tries to simplify until there are primitive types to then copy by value.
Definition:
CS
current source typeCT
current target typeNS
next source typeNT
next target type
generate(CS, CT)
:
- if
extend
method existsfunc(CS) CT
:- use it
- method generation finished
- if
useUnderlyingTypeMethods
is enabled:- and if
extend
method exists for a underlying type- use it
- method generation finished
- and if
- if
skipCopySameType
is enabled andCS==CT
:- use source value
- method generation finished
CS is primitive
andCT is primitive
andCS=CT
- copy source value
- method generation finished
CS is *NS
andCT is *NT
:- check for
nil
andgenerate(NS, NT)
- check for
CS
is not a pointer andCT is *NT
:- get pointer of
generate(CS, NT)
- get pointer of
- if
CS is *NS
andCT
is not pointer anduseZeroValueOnPointerInconsistency
is enabled:- if
CS
isnil
: use zero value ofCT
otherwise:generate(NS, CT)
- if
CS is []NS
andCT is []NT
- iterate over the slice
- convert slice item:
generate(NS, NT)
- convert slice item:
- iterate over the slice
CS is map[Key-NS]Value-NS
andCT is map[Key-NS]Value-NT
- iterate over the map
- convert the key:
generate(Key-NS, KEY-NT)
- convert the value:
generate(Value-NS, Value-NT)
- convert the key:
- iterate over the map
CS is struct
andCT is struct
:- for each TargetField(TF) in CT:
- if
TF
isignore
d- skip
- if
TF
is unaccessible andignoreUnexported
is not enabled:- error: cannot use unexported types
- get SourceField(SF)
- from
map
if defined - otherwise:
- try to find field with same name from
CS
- try to find field in paths defined in
autoMap
- field matching is case insensitive if
matchIgnoreCase
is enabled)
- try to find field with same name from
- from
- if
SF
is a method onCS
:- call
SF
- call
- if mapping method MF is defined
- execute
MF(SF) MappingTarget
- ensure
MappingTarget
==typeof TF
- execute
- else
generate(SF) TF
- if
- for each TargetField(TF) in CT:
- error:
CS
cannot be automatically converted toCT
.