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:
CScurrent source typeCTcurrent target typeNSnext source typeNTnext target type
generate(CS, CT):
- if
extendmethod existsfunc(CS) CT:- use it
- method generation finished
- if
useUnderlyingTypeMethodsis enabled:- and if
extendmethod exists for a underlying type- use it
- method generation finished
- and if
- if
skipCopySameTypeis enabled andCS==CT:- use source value
- method generation finished
CS is primitiveandCT is primitiveandCS=CT- copy source value
- method generation finished
CS is *NSandCT is *NT:- check for
nilandgenerate(NS, NT)
- check for
CSis not a pointer andCT is *NT:- get pointer of
generate(CS, NT)
- get pointer of
- if
CS is *NSandCTis not pointer anduseZeroValueOnPointerInconsistencyis enabled:- if
CSisnil: use zero value ofCTotherwise:generate(NS, CT)
- if
CS is []NSandCT 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-NSandCT 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 structandCT is struct:- for each TargetField(TF) in CT:
- if
TFisignored- skip
- if
TFis unaccessible andignoreUnexportedis not enabled:- error: cannot use unexported types
- get SourceField(SF)
- from
mapif 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
matchIgnoreCaseis enabled)
- try to find field with same name from
- from
- if
SFis 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:
CScannot be automatically converted toCT.