Skip to content

Releases: switchupcb/copygen

v0.3.0

14 Apr 00:45
Compare
Choose a tag to compare

Copygen v0.3

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.3 adds the ability to use the generator programmatically from any step of the program. Implement custom loaders, matchers, and generator functions, or pass .yml files similar to the command line interface.

Schema

The schema has remained stable and includes the addition of 2 new options: tag and automatch. The tag option allows you to match by tag, while the automatch option allows you to explicitly and/or selectivity invoke the existing automatcher. Go text/templates that use the .tmpl extension are now supported; with no extra effort required. Simply use them in the same way you would use a .go template.

For more information, view the options table.

Parser

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

Matcher

The matcher's stability has been an improved. Issues regarding fields with similar names/definitions resulting in duplicate fields have been resolved.

Generation

NEW to Copygen's generation capabilities is the ability to generate code using text/templates (.tmpl) AND generate code programmatically. Implement custom loaders, matchers, and generator functions, or pass .yml files similar to the command line interface. Get started by viewing the program example.

.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.4 if gomacro's issues are fixed. Otherwise, support for .tmpl generation is still in a beta stage.

For more information, read about Templates.

Project Structure

The parser has been simplified with a go/types implementation. Options have been refactored and feature a better explanation in the Contributing Guideline.

Other

Copygen ranks highly for its keyword on search engines and is featured in this article: What Is Copygen?

Future

Copygen v0.4 will focus on stability improvements and an expansion of generation features for all parse-able types. For more information, check out the Roadmap.

Missing Features

Copygen is only "missing" one major feature (that is implementable through convert customization): Deepcopy. As stated in the last release, the ideal deepcopy option allows the user the from-fields that will be deepcopied using regex. Support for the deepcopy option requires improvements to the generator, which is the focus of v0.4. However, there is no guarantee that deepcopy will be implemented at that time.

Disclaimer

Copygen will not be assigned with v1.0.0 until its functionality is more solidified. A GPL License has been added, along with the ability to purchase license exceptions to support further development. This does not affect the ability for people to generate proprietary code, but does protect modifications to Copygen.

For more information, read What Can I Do?

v0.2.4

26 Oct 04:07
Compare
Choose a tag to compare

go install can't be used with directives so we must replace the interpreter fork with a harder version (that doesn't use replace in the go mod until it's implemented upstream.

Template Support

19 Oct 02:42
Compare
Choose a tag to compare

This release provides full template support. Go modules may be unsupported.

yaegi does not support Go modules in its current state. We've created a Pull Request upstream, but it's been assigned with a "longer-term" tag after a month. As a result, the repository uses an up-to-date fork in order to provide support for Go Modules in templates. If there are any bugs with template imports, please refer to traefik/yaegi#1265.

v0.2.2

17 Oct 03:52
Compare
Choose a tag to compare

This patch fixes an issue with alias package imports on types, cyclic types, and makes the Depth mechanic consistent across all types.

v0.2.1

09 Oct 22:34
Compare
Choose a tag to compare

This patch fixes any issues regarding special-case third party imports.

v0.2.0

05 Oct 09:31
Compare
Choose a tag to compare

Copygen v0.2.0

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.

Schema

The schema has changed compared to v0.1. Only configuration options (filepaths and custom generator options) are defined in the YML. The current schema is inspired by goverter with a few changes to increase the simplicity of the UI: The user modifies a .go interface to specify types rather than having to manipulate a YML.

Supported options (convert, depth, map, custom) can be used without an indicator and in addition to external comments (which is kept with generated code). These can be used on convert functions and mapping functions which are defined in the setup.go file. External package types are supported by Copygen v0.2, as they were in v0.1.

Users are able to create functions within the UI and have them kept along with generated code.

Matcher

The matcher has kept the same functionality but been simplified. All the fields (including subfields) will be collected for each type and compared. A map option will determine whether the automatcher is used or not.

Generation

Templates are still waiting on a Pull Request. We will consider using a working-fork if this isn't supported in the upstream library by v0.3.

Project Structure

The project has refactored its structure to better model the steps it takes in generating code. The majority of the complexity lies in the parser, which is updated when options are changed, or an edge-case (i.e channels, etc) is found. The documentation has been updated.

Disclaimer

Copygen — being 14 days old — is still in its early stages. As a result, it will not be assigned with v1.0.0 until its functionality is more solidified.

Future

Copygen is only "missing" one major feature (that is implementable through convert customization): Deepcopy. Ideally, the user is able to specify the from-fields that will be deepcopied. This information will be used at generation time (cli/generator -> templates/template.go) in order to generate the correct deepcopy code depending on a field's definition (i.e struct -> direct, int -> direct, slice -> loop, etc) and primitive sub-field definitions _(i.e int, string, etc subfield in struct). Support for the deepcopy option is already implemented: Only modifications to the generator are required.

This feature may or may not be included in v0.3 which will be focused on stability through quality control (tests, workflows, edge-cases, etc).

Allocation

One other feature that may or may not be included is the addition of allocations when pointers aren't used on to-types. Including this feature is debatable because the user is always able to create a new type prior to calling a Copygen function. In contrast, adding allocation would only change the user's workflow by moving a variable's assignment (to catch the result of a Copygen function). Each method has little — if no — difference in performance. This feature would require a template change (or addition) equivalent to the deepcopy feature.

v0.1.0

29 Sep 07:15
Compare
Choose a tag to compare

Copygen v0.1.0

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. This makes it 391x faster than the reflection based solution copier with the aim of also being faster to use. Copygen features an entire README, Project Structure, and Roadmap that will speed up the time it takes to be fully-featured.

Schema

Every code generation tool has its own schema. While some generators are able to use a specific layer as a single source of truth (i.e SQL, GraphQL, etc), this is harder to do due to the nature of copygen. The "schema" of copygen is defined partially in your code, and partially in a YML file that adds full fledged customization of generated code via converters (and templates once interpretation is available). As of now, we have a pull request ready to solve the template roadblock.

Matcher

Copygen features an automatcher that makes mapping domain models to data models take less time with an out-of-the-box solution. This AST-based automatcher supports depth and is not coupled with a specific loader. The YML provides the ability to manually map fields to other fields if preferred.

Generation

Copygen aims to be more customizable with its templates. Users will be able to use the Go language to create func-based template algorithms without having to fork the project. The user will be provided all the field information one is provided in the default program, with the ability to truly customize their program using custom options. For this reason, more examples are encouraged over focus on implementation because copygen is a tool for code generation, but doesn't define it.

Project Structure

The project has a general structure that aims to decouple functionalities with eachother. Models, Loaders, and Generators help with building the program piece by piece. Documentation is prioritized.

Disclaimer

Copygen — being 7 days old — is still in its early stages. As a result, it will not be assigned with v1.0.0 until its functionality is more solidified. Future minor version changes may be breaking._