Skip to content

Releases: switchupcb/copygen

v0.4.0

27 Jun 09:41
e824269
Compare
Choose a tag to compare

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.

v0.3.9

22 Jun 08:40
Compare
Choose a tag to compare

This patch fixes a potential mismatch of options to functions that are declared in non-alphabetical order and improves stability with regards to comment-parsing. Copygen outputs functions in their declared order, rather than alphabetical order (similar to versions prior to v3).

v0.3.8

07 Jun 20:59
Compare
Choose a tag to compare

This patch fixes permission errors on MacOS and issues with collected type imports being excluded from collection types.

v0.3.7

22 May 21:03
Compare
Choose a tag to compare

This patch fixes any issues with custom option parsing.

v0.3.6

17 May 15:31
Compare
Choose a tag to compare

This release adds the ability to disable the matcher from the command-line using -xm or programmatically by setting Enviroment.DisableMatcher = true. In addition, examples (and its packages) are no longer included in the go install binary or go get module.

v0.3.5

05 May 20:23
Compare
Choose a tag to compare

godoc update

v0.3.4

29 Apr 23:09
Compare
Choose a tag to compare

Parser

This patch fixes any issues with collection types that use pointers. It also fixes an import-issue with an obscure, but possibly common 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. Cyclic type output is more intuitive due to parser refactoring.

Generator

Imports are now resolved in the generated file's output: This feature is also supported in code generated by custom templates.

v0.3.3

28 Apr 07:24
Compare
Choose a tag to compare

The project has been updated to go 1.18.

Parser

This patch reimplements support for interfaces, fixes func parsing, and prevents any issues with cyclic types from occurring. Caching has been refactored to prevent unintended behavior, while also improving parsing performance. In addition, *all types have been tested: This means that there should be no more edge-cases regarding the current supported types. In other words, the ability to parse every Go type including basic, array, slice, map, chan, interface, func, and every combination in-between is supported.

Matcher

The matcher will match pointers of any type and handle their semantics. For example, using tb **bool and fb *bool will result in tb = &fb.

Other

Copygen has been mentioned in awesome-go.

v0.3.2

25 Apr 01:19
Compare
Choose a tag to compare

Parser

This patch fixes any issues regarding composite, function, and complex types with packages. It also fixes an duplicate variables names (added in the go/types parser refactor). As a result, there may be unknown issues regarding complex cyclic types. Support for interfaces is temporarily removed.

Matcher

This patch prevents a typefield's subfields from matching with another typefield's subfields, when that other typefield is already matched with the typefield itself. It also defines a one-to-many matcher behavior in relation to to-from fields (where a to-field can only have one match; from-field can have multple). This may have implications with regards to manual mapping which we will deal with on a case-by-case basis.

Generator

Pointer semantics are fixed when copying pointers to non-pointers.

v0.3.1

23 Apr 23:22
Compare
Choose a tag to compare

This patch fixes any issues regarding basic type-field parsing and matching.

Parser

All types are officially supported.

Generator

  • The .go generate template uses strings.Builder.
  • .tmpl base template requires refactor.
  • Template consistency throughout the application has been fixed.
  • The roadmap has been updated.

Cyclic Functionality Refactor

In previous versions of Copygen, cyclic types were only partially parsed (intended). Parsing cyclic types have been refactored such that cyclic types are now FULLY parsed. This means that the user must be sure to handle any circular pointers. For example, a field that contains a subfield, which is also contained in subfield.Fields (or any of the subfield's subfields...).

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 PrintFieldRelations between to-type and from-type fields. As a result, the method only directly compares the given field slices (as opposed to ALL subfields).