The invention relates to the technical field of
computer programming, and discloses a Go language structural body automatic
conversion method and
system. The method comprises the following steps: firstly, receiving definitions of a
source structure body and a target structure body as input, automatically matching fields of the two structure bodies through a
field mapping rule engine according to a preset rule, and generating a
field mapping relationship; then, based on the
field mapping relation, a code generator is used for automatically generating a conversion code containing field assignment and
type conversion logic; finally, the generated conversion codes are compiled into an
executable conversion function, and the function can convert data in the
source structure instance according to the field mapping relation during program running and fill the data into the target structure instance. According to the method,
automation of structural body conversion is achieved, the problem that errors are prone to occurring when conversion codes are written manually is solved, and the
maintainability of the codes is improved; the mode of reflection during operation is replaced by
code generation, so that the conversion efficiency is remarkably improved; meanwhile, the method supports batch conversion and concurrent
processing, and can meet the performance requirements of large-scale
data processing.