Top 16 Go Code-Generator Projects
Swagger 2.0 implementation for goProject mention: Show me your REST APIs 😊 | reddit.com/r/golang | 2021-12-15
You have things like https://github.com/go-swagger/go-swagger. Where the generated code is not 100% vanilla, not ideal.
Generate type-safe code from SQLProject mention: Is it a good practice to make a wrapper around database? | reddit.com/r/golang | 2022-01-13
Maybe take a look at sqlc (https://sqlc.dev). It nicely wraps/abstracts the database interaction with a database package. Makes it really easy to write "type safe" sql code without the problems you might run into when using object relational mappers.
Less time debugging, more time building. Scout APM allows you to find and fix performance issues with no hassle. Now with error monitoring and external services monitoring, Scout is a developer's best friend when it comes to application development.
Automatically generate Go test boilerplate from your source code.Project mention: Share your must-know Go development tips | reddit.com/r/golang | 2021-12-26
Command line tool to generate idiomatic Go code for SQL databases supporting PostgreSQL, MySQL, SQLite, Oracle, and Microsoft SQL Server (by xo)Project mention: We Went All in on Sqlc/Pgx for Postgres and Go | news.ycombinator.com | 2021-09-08
I'm a big fan of the database first code generator approach to talking to an SQL database, so much so that I wrote pggen (not to be confused with pggen, as far as I can tell a sqlc fork, which I just recently learned about).
I'm a really big partisan of this approach, but I think I'd like to play the devil's advocate here and lay out some of the weaknesses of both a database first approach in general and sqlc in particular.
All database first approaches struggle with SQL metaprogramming when compared with a query builder library or an ORM. For the most part, this isn't an issue. Just writing SQL and using parameters correctly can get you very far, but there are a few times when you really need it. In particular, faceted search and pagination are both most naturally expressed via runtime metaprogramming of the SQL queries that you want to execute.
Another drawback is poor support from the database for this kind of approach. I only really know how postgres does here, and I'm not sure how well other databases expose their queries. When writing one of these tools you have to resort to tricks like creating temporary views in order infer the argument and return types of a query. This is mostly opaque to the user, but results in weird stuff bubbling up to the API like the tool not being able to infer nullability of arguments and return values well and not being able to support stuff like RETURNING in statements. sqlc is pretty brilliant because it works around this by reimplementing the whole parser and type checker for postgres in go, which is awesome, but also a lot of work to maintain and potentially subtlety wrong.
A minor drawback is that you have to retrain your users to write `x = ANY($1)` instead of `x IN ?`. Most ORMs and query builders seem to lean on their metaprogramming abilities to auto-convert array arguments in the host language into tuples. This is terrible and makes it really annoying when you want to actually pass an array into a query with an ORM/query builder, but it's the convention that everyone is used to.
There are some other issues that most of these tools seem to get wrong, but are not impossible in principle to deal with for a database first code generator. The biggest one is correct handling of migrations. Most of these tools, sqlc included, spit out the straight line "obvious" go code that most people would write to scan some data out of a db. They make a struct, then pass each of the field into Scan by reference to get filled in. This works great until you have a query like `SELECT * FROM foos WHERE field = $1` and then run `ALTER TABLE foos ADD COLUMN new_field text`. Now the deployed server is broken and you need to redeploy really fast as soon as you've run migrations. opendoor/pggen handles this, but I'm not aware of other database first code generators that do (though I could definitely have missed one).
Jennifer is a code generator for GoProject mention: Boilerplate for experienced devs | reddit.com/r/golang | 2021-12-14
I just spent a few hours writing a crapload of boilerplate code generation code with jennifer, if that helps any.
binary serialization format
Type safe SQL builder with code generation and automatic query result data mapping (by go-jet)Project mention: Sql generator but for SQLite | reddit.com/r/golang | 2021-12-26
Jet has full support for SQLite. https://github.com/go-jet/jet
OPS - Build and Run Open Source Unikernels. Quickly and easily build and deploy open source unikernels in tens of seconds. Deploy in any language to any cloud.
K8s Go client code generator from Kubernetes resource yamlsProject mention: We know how boring and time-consuming it is to map K8s resource YAML into an unstructured object. Here is a tool to auto-generate dynamic client go code | reddit.com/r/kubernetes | 2021-11-09
kyaml2go generated Go code for equivalent kubectl operations on k8s resource. It can generate code with the typed client and dynamic client. We don't have to figure out which k8s packages to import and waste time in populating the resource objects. You can give it a try at: https://kyaml2go.prasadg.dev. Whereas, https://github.com/mholt/json-to-go is totally different tool for different use case. It generated Go type definitions (structs) from JSON. But for K8s resources, we don't have to generate Go type as they are already defined in the `k8s.io/api` packages. kyaml2go helps you finding correct packages and populate the struct as per the yaml specs and call correct methods to manage the resource.
The High Code Framework (low-code for devs)Project mention: Cue: A new language for data validation | news.ycombinator.com | 2021-10-19
There is "cue vet" for command line validation.
Are you more interested in validation in APIs?
There are interesting use cases for ETL. I have written a tool that generates full-stack code using CUE as the declarative input for your types. (https://github.com/hofstadter-io/hof)
I no longer use Helm now that I use CUE, at least I no longer write charts. We do need a Helm like workflow tool built on CUE to replace the text/templating of Yaml
Collection of useful patterns (by donutloop)
XSD (XML Schema Definition) parser and Go/C/Java/Rust/TypeScript code generator
Deep copy generatorProject mention: Are structs and pointers to them deep-copied by default? | reddit.com/r/golang | 2021-12-31
Easy to use universal code/text generatorProject mention: Transforming json data with easygen | dev.to | 2021-12-30
there are lots of other transformation support function already builtin inside easygen, check out the full list with sample usage and results here.
An opinionated OpenAPI v3 code generator for Go. Use this to generate API models and router scaffolding.Project mention: Openapi-generator-go – Generate go code from an openapi spec | news.ycombinator.com | 2021-10-18
A hof generator for Golang CLIsProject mention: Bashly – Create beautiful bash scripts from simple YAML configuration | news.ycombinator.com | 2021-08-25
Shameless plug, I wrote https://github.com/hofstadter-io/hof as a generalized tool for what this does, i.e. generate boilerplate from a DSL.
https://github.com/hofstadter-io/hofmod-cli is the same idea for generating Go CLI boilerplate.
hof uses CUE instead of Yaml, can output to any and multiple languages, and uses diff3 so you can work in both the output and the design at the same time.
Easily generate golang source from templates. (by fluhus)Project mention: go:generate using go templates | reddit.com/r/golang | 2021-09-08
Go Code-Generator related posts
Is it a good practice to make a wrapper around database?
1 project | reddit.com/r/golang | 13 Jan 2022
Style/Pattern for Go Database, DTO& Validation Struct
1 project | reddit.com/r/golang | 9 Jan 2022
How not to bleed implementation details (transaction) in the HTTP Handler?
1 project | reddit.com/r/golang | 6 Jan 2022
Transforming json data with easygen
2 projects | dev.to | 30 Dec 2021
Share your must-know Go development tips
7 projects | reddit.com/r/golang | 26 Dec 2021
Exiting the Vietnam of Programming: Our Journey in Dropping the ORM (in Golang)
1 project | reddit.com/r/golang | 27 Nov 2021
1 project | reddit.com/r/devopskhan | 29 Oct 2021
What are some of the best open-source Code-Generator projects in Go? This list will help you:
Are you hiring? Post a new remote job listing for free.