oNaiPs / go-generate-fast

Enhanced version of go generate
MIT License
26 stars 0 forks source link

go-generate-fast

build Go Report
Card

πŸš€ Shave off minutes and turn them into seconds for your go generation step πŸš€.

go-generate-fast serves as a drop-in replacement for go generate.

Smart enough to understand if your generated files have changed or not, go-generate-fast can circumvent running unaltered scripts, offering a significant speed boost by harnessing smart caching mechanisms.

https://github.com/oNaiPs/go-generate-fast/assets/374130/396a0160-90f8-46d0-a05c-783d127a384e

Features

Install

go install github.com/oNaiPs/go-generate-fast

Usage

Replace the traditional go generate command with go-generate-fast in your scripts to leverage its benefits.

Typical command invocation is as follows:

go-generate-fast [file.go... | packages]

Supported Tools

go-generate-fast automatically detects the input/output files for the following tools:

Above commands can be called in binary form, or with go run. E.g.:

//go:generate stringer

OR

//go:generate go run golang.org/x/tools/cmd/stringer[@latest]

Custom Input/Output Files

If you are using a custom or currently unsupported script/tool, you can manually add files as demonstrated below:

//go:generate_input doc/gen_docs.go commands/**/*.go
//go:generate_output doc/man/*.1 doc/md/*.md
//go:generate go run doc/gen_docs.go

//go:generate_input images/*.png
//go:generate_output images/*.jpeg
//go:generate bash convert_images.sh

Just before your go:generate command, you can add any go:generate_input or go:generate_output directives accurately. The input files influence the tool/script (re)execution, while output files contain the results. If one or more input files change, the command reruns and stores the output files in the cache directory.

Configuration

Various environment variables are available for configuration:

How it Works

go-generate-fast makes regeneration faster by reusing previously outputs when the same input files are used again. This approach is identified via the creation of a unique hash that combines inputs,outputs and other metadata. The underlying concept is similar to the C/C++ compiler cache ccache.

Contributing

We highly appreciate community contributions! Please create an issue or submit a pull request for any suggestions or issues.

License

go-generate-fast is licensed under the MIT License.