Go Code-Generator

Open-source Go projects categorized as Code-Generator | Edit details

Top 16 Go Code-Generator Projects

  • GitHub repo GoSwagger

    Swagger 2.0 implementation for go

    Project 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.

  • GitHub repo sqlc

    Generate type-safe code from SQL

    Project 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.

  • Scout APM

    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.

  • GitHub repo gotests

    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
  • GitHub repo xo

    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[1] (not to be confused with pggen[2], 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).

    Also the article is missing a few more tools in this space. https://github.com/xo/xo. https://github.com/gnormal/gnorm.

    [1]: https://github.com/opendoor/pggen

  • GitHub repo jennifer

    Jennifer is a code generator for Go

    Project 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.

  • GitHub repo colfer

    binary serialization format

  • GitHub repo jet

    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

    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.

  • GitHub repo kyaml2go

    K8s Go client code generator from Kubernetes resource yamls

    Project 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.

  • GitHub repo hof

    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

  • GitHub repo toolkit

    Collection of useful patterns (by donutloop)

  • GitHub repo xgen

    XSD (XML Schema Definition) parser and Go/C/Java/Rust/TypeScript code generator

  • GitHub repo deep-copy

    Deep copy generator

    Project mention: Are structs and pointers to them deep-copied by default? | reddit.com/r/golang | 2021-12-31
  • GitHub repo easygen

    Easy to use universal code/text generator

    Project 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.

  • GitHub repo openapi-generator-go

    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
  • GitHub repo hofmod-cli

    A hof generator for Golang CLIs

    Project 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.

  • GitHub repo goat

    Easily generate golang source from templates. (by fluhus)

    Project mention: go:generate using go templates | reddit.com/r/golang | 2021-09-08
NOTE: The open source projects on this list are ordered by number of github stars. The number of mentions indicates repo mentiontions in the last 12 Months or since we started tracking (Dec 2020). The latest post mention was on 2022-01-13.

Go Code-Generator related posts


What are some of the best open-source Code-Generator projects in Go? This list will help you:

Project Stars
1 GoSwagger 7,129
2 sqlc 4,658
3 gotests 3,622
4 xo 2,980
5 jennifer 2,277
6 colfer 645
7 jet 596
8 kyaml2go 263
9 hof 185
10 toolkit 142
11 xgen 129
12 deep-copy 99
13 easygen 49
14 openapi-generator-go 23
15 hofmod-cli 16
16 goat 0
Find remote jobs at our new job board 99remotejobs.com. There are 29 new remote jobs listed recently.
Are you hiring? Post a new remote job listing for free.
Deliver Cleaner and Safer Code - Right in Your IDE of Choice!
SonarLint is a free and open source IDE extension that identifies and catches bugs and vulnerabilities as you code, directly in the IDE. Install from your favorite IDE marketplace today.