Go Code-Generator

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

Top 15 Go Code-Generator Projects

  • GitHub repo GoSwagger

    Swagger 2.0 implementation for go

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

  • GitHub repo sqlc

    Generate type safe Go from SQL

    Project mention: A simple SQL parser in Go | reddit.com/r/golang | 2021-12-02

    Maybe he's thinking of sqlite support for sqlc:

  • Nanos

    Run Linux Software Faster and Safer than Linux with Unikernels.

  • GitHub repo gotests

    Automatically generate Go test boilerplate from your source code.

    Project mention: gotests | reddit.com/r/devopskhan | 2021-10-29
  • 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

  • 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: [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

    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.

  • 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 easygen

    Easy to use universal code/text generator

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

  • 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 2021-12-02.

Go Code-Generator related posts

Index

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

Project Stars
1 GoSwagger 7,026
2 sqlc 4,430
3 gotests 3,561
4 xo 2,966
5 jennifer 2,224
6 colfer 638
7 jet 548
8 kyaml2go 260
9 hof 177
10 toolkit 140
11 xgen 122
12 easygen 47
13 openapi-generator-go 20
14 hofmod-cli 16
15 goat 0
Find remote jobs at our new job board 99remotejobs.com. There are 32 new remote jobs listed recently.
Are you hiring? Post a new remote job listing for free.
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com