Skip to content

v0.4.0

Latest
Compare
Choose a tag to compare
@switchupcb switchupcb released this 27 Jun 09:41
· 6 commits to main since this release
e824269

Copygen v0.4

Copygen is a command-line code generator that generates type-to-type and field-to-field struct code without adding any reflection or dependencies to your project. Copygen v0.4 adds the ability to disable the matcher from the command-line and includes a number of patches for increased stability.

Schema

The schema has remained stable.

Parser

The ability to parse every Go type including basic, array, slice, map, chan, interface, and func types has been tested.

The following issues in the parser have been fixed:

  • any issues regarding basic type-field parsing and matching.
  • any issues regarding composite, function, and complex types with packages.
  • any issues with collection types that use pointers.
  • any issues with duplicate variables names.
  • any issues with collected type imports being excluded from collection types.
  • any issues with custom option parsing.
  • permission errors on MacOS.
  • edge case where the setup file's package is the same as the output file's package, and the setup file uses definitions from the output file's package is handled.
  • potential mismatch of options to functions that are declared in non-alphabetical order.
  • caching has been refactored to prevent unintended behavior while also improving parsing performance.

Cyclic Functionality Refactor

In previous versions of Copygen, cyclic types were only partially parsed (as intended). In Copygen v0.4, cyclic types are FULLY parsed. This means that you must be sure to handle any circular pointers such as a field that contains a subfield, which is also contained in that subfield.Fields (or any of the subfield's subfields, etc).

Matcher

The matcher's stability has been improved with regards to typefield-matching. The matcher models a one-to-many relationship (one to-field to many from-fields).

Generation

Pointer semantics are fixed when pointers are copied to non-pointers. Imports are now resolved in the generated file's output: This feature is also supported in code generated by custom templates.

Support for .tmpl generation is implemented and no longer in a beta stage. .go template support for third-party modules (in the template file itself; NOT the setup) is still awaiting a pull request. This may be fixed in v0.5 if gomacro's issues are fixed.

For more information, read about Templates.

Debug

The debug method CountFields has been removed. Use field.AllFields to get the length of every field in a field (including itself) or field.Fields to get the length of the field's fields. In a similar manner, field.AllFields can be used to PrintFieldRelation between to-type and from-type fields. As a result, the method only directly compares the given field slices (as opposed to ALL subfields).

Project Structure

Example files are no longer included in the built copygen binary.

Other

Copygen has been mentioned in awesome-go.
Copygen has been tested at scale in Disgo.

Future

Copygen v0.5 will focus on adding new options. For more information, check out the Roadmap. A bounty for an issue has been added: Claim a Reddit Gold by solving the issue with setup file declared free-floating comments.

Missing Features

Copygen is only "missing" one major feature (that is implementable through convert customization): Deepcopy. The ideal deepcopy option allows the user the from-fields that will be deepcopied using regex. Support for the deepcopy option may be added in v0.5.

Disclaimer

Copygen will be assigned with v1.0.0 when its functionality remains stable over two minor versions.