What is Copygen?

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.
Apr 13, 2022
3 min

While creating an automated royalty management solution, I needed a way to speed up programming development (that would also be subject to change in the future). Instead of compromising the application's design by sacrificing iterability for short-term code-speed, I decided to use code generation: Generated code would allow the program to maintain a resilient design at no cost; with the added bonus of being usable on future projects.

To understand how Copygen plays a role in this process, you need to understand how a maintainable application is designed. Just as there are multiple ways to build a house, there are also multiple ways to build a software application. In real life, a person can haphazardly put a hut together and call it a day, but the hut will be knocked over as soon as the wind blows. In contrast, a well-designed fortress will stand up against the strongest circumstances that even missiles struggle to destroy. One structure is easier to build (with regards to time), but the other is easier to maintain.

The significance of Copygen lies where it fits as a tool to generate maintainable code; which has many benefits (especially with regards to collaboration). The use-case for Copygen is described here: When to Use Copygen. Copygen's customizability gives it many potential use cases. However, Copygen's main purpose is to save you time by generating boilerplate code to map objects together.


Create a customizable code generator for Go that generates type-to-type and field-to-field struct code without adding any reflection or dependencies to a project.

How It Works

All information pertaining to the technical details of Copygen can be found on Github: https://github.com/switchupcb/copygen.

Project Timeline

The project timeline can be viewed using Git Commit History: I spent 14 days creating version 0.1.0 of Copygen which was released on September 29th, 2021. Upon completion, I created a post on Reddit which led to a user asking me to compare Copygen vs. Goverter. The consensus was that Copygen maintained more capability, but a worse User Interface (UI) so I took inspiration… I'd spend 6 more days optimizing the project and implementing an improved UI which solidified Copygen’s dominance as a field-to-field code generator (in Go). Changes at this scale and speed were only possible due to the application design decisions I’d made in the first version.

Copygen version 0.2.0 was released on October 5th, 2021. There were a few edge cases that popped up over the course of the month that were promptly resolved and support for customization templates (using the Go language rather than go/templates) was added in version 0.2.3. However, the interpreter I used to implement this feature did not support Go modules. This issue occurred due to the way the interpreter library handled imports (which assumed the user used Linux). I created a pull request for this issue which is still pending.

Copygen version 0.3.0 was started on April 5th, 2022 and released on April 13th, 2022... all with a broken keyboard. This version heavily improved the stability of the code generator and added a host of new features. Developers are now able to create custom loaders, matchers, and generator functions, and pass files as they would normally programmatically. You can track the release progress of Copygen on Github.


I’ve used Copygen on a number of upcoming projects in order to keep them maintainable while saving time spent typing. Copygen allows me to spend this time on other tasks while keeping my applications performant. While it’s designed to reduce field-to-field boilerplate code (that isn’t avoidable by using generics), it also can be used as a custom code generator. The current software environment provides a number of ways to store your data: There are relational, graph, key-value, query-based, document-based, and other types of databases. Without Copygen, changing any of these things along with the business-case risks outlining your entire repository in red.

Read More

improve Your Mindset

Unsubscribe at any time. See Privacy Policy