π 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
go:generate
tools, including
stringer,
mockgen,
esc, and more.go install github.com/oNaiPs/go-generate-fast
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]
go-generate-fast
automatically detects the input/output files for the
following tools:
fmt.Stringer
interface.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]
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.
Various environment variables are available for configuration:
GO_GENERATE_FAST_DIR
: Sets the base directory for configurations and
caching. Default locations differ by OS:
$HOME/.config/go-generate-fast
$HOME/Library/Application Support/go-generate-fast
%AppData%\go-generate-fast
GO_GENERATE_FAST_CACHE_DIR
: Defines the cache files location. Default is
$GO_GENERATE_FAST_DIR/cache/
.
GO_GENERATE_FAST_DEBUG
: Enables debugging logs.
GO_GENERATE_FAST_DISABLE
: Completely ignores caching.
GO_GENERATE_FAST_READ_ONLY
: Uses the existing cache but prevents any new
cache entries.
GO_GENERATE_FAST_FORCE_USE_CACHE
: Forceably uses cache. If it does not exist, the command fails.
GO_GENERATE_FAST_RECACHE
: Sets the cache to overwrite existing entries. The
new results will be cached.
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.
We highly appreciate community contributions! Please create an issue or submit a pull request for any suggestions or issues.
go-generate-fast
is licensed under the MIT License.