Top 15 Go Code-Generator Projects
Swagger 2.0 implementation for goProject mention: Looking for help with Azure Autorest | reddit.com/r/golang | 2021-10-04
You may have better luck with go-swagger or OpenAPI Generator to generate Go code.
Generate type safe Go from SQLProject mention: A simple SQL parser in Go | reddit.com/r/golang | 2021-12-02
Maybe he's thinking of sqlite support for sqlc:
Run Linux Software Faster and Safer than Linux with Unikernels.
Automatically generate Go test boilerplate from your source code.Project mention: gotests | reddit.com/r/devopskhan | 2021-10-29
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 Go
binary serialization format
Type safe SQL builder with code generation and automatic query result data mapping (by go-jet)Project mention: [HELP]One to many in sqlx. | reddit.com/r/golang | 2021-11-22
Had a similar issue and the only Go library I've found, that can do such a scan automatically for you is this one: https://github.com/go-jet/jet.
Scout APM: A developer's best friend. Try free for 14-days. Scout APM uses tracing logic that ties bottlenecks to source code so you know the exact line of code causing performance issues and can get back to building a great product faster.
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
Easy to use universal code/text generatorProject mention: Maintenance free system multi booting | dev.to | 2021-10-28
In this article, we'll first look at those few more boilerplates that enable you to only write the above few lines and everything will work out magically. Then we'll move on to how to make things even simpler, with the help of easygen.
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
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
Maintenance free system multi booting
1 project | dev.to | 28 Oct 2021
Journey towards a maintenance free system booting
1 project | dev.to | 27 Oct 2021
Openapi-generator-go – Generate go code from an openapi spec
1 project | news.ycombinator.com | 18 Oct 2021
Compile SQL to type-safe Go
1 project | reddit.com/r/AgnosTechValley | 30 Sep 2021
go:generate using go templates
1 project | reddit.com/r/golang | 8 Sep 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.