Flexible code generation tool which perfectly integrates with your project.
- Extensible, versioned and widely customizable code generators
- Verbose code generation config
- Convenient API for fastest creation of new code generators
- It's hard to make a custom AST walker. You work with already parsed go code which is most convenient for almost all cases.
- Working only with go modules system (GO111MODULE=on).
Beta-version. Not recommended to use it in production.
The main goal of gen is to make code generation more flexible and easy to maintain.
Using gen you need only gen
cli utility and gen.yml
file (see its description), where you could describe code generation details.
- Install
gen
by running$ go get github.com/cv21/gen/cmd/gen
- Add
gen.yml
to your project root (see examples directory in this project) - Run
$ gen
inside your project root
Repository | Description | Status |
---|---|---|
gen-generator-base | Generates basis for gen generator | Released |
gen-interface-mock | Generates mocks from interface | Released |
gen-interface-exchanges | Generates exchanges from interface methods signatures | Released |
gen-logging-middleware | logging middleware generator | Coming soon |
gen-gokit-http | Generates HTTP transport for go-kit from interface | Coming soon |
gen-gokit-grpc | Generates gRPC transport for go-kit from interface | Coming soon |
... | ... | ... |
* You can use other or make your own generator for gen
* Feel free to contibute your generators to this page
Typical gen.yml
consists of files
config array.
Each of files
consists of:
path
- Path to source file which will be passed to specified generator.repository
- Link to generator repository. It supports standard Golang module queries for versioning.params
- Custom params for generator.
gen.yml
example:
files:
- path: ./path_to_some_source_file.go
repository: github.com/some/[email protected]
params:
some_generator_custom_param: some_value
- path: ./path_to_some_another_file.go
repository: github.com/another/name-of-generator@master
params:
another_generator_custom_param: other_value
- Ability to use
go:generate
instead ofgen.yml
for short plugin configurations as a lightweight but yet powerful, versioned and flexible code generation system.