protoc-gen-tpl is a plugin for protobuf compiler (protoc) which allows to generate files using custom templates and rules.
See in checklist implemented and planned features.
You need protobuf compiler. See instructions on Protocol Buffers site.
Install on Linux using apt
apt install protobuf-compilerInstall on macOS using Homebrew
brew install protobufInstall protoc-gen-tpl plugin using go
go get github.com/apoprotsky/protoc-gen-tpl
Example how to generate go code from proto files
mkdir examples/out
protoc \
--tpl_out=examples/out \
--tpl_opt=prefix=github.com/apoprotsky/protoc-gen-tpl/examples/ \
--tpl_opt=lang=go \
--tpl_opt=lang=ts \
--tpl_opt=lang=php \
examples/proto/*.protoOption prefix has same behaviour as module=$PREFIX for go plugin.
Option lang designates which languages to use for output files. This option can be specified multiple times.
- Generate
gofiles fromprotofiles - Generate structs types from messages
- Generate struct fields tags
- Generate json tags
- Generate custom tags
- Generate types from enumerations
- Generate constants from enumerations
- Supported struct fields types:
- Scalar types (string, numbers)
- Arrays
- Message type
- Enumeration type
- Generate
tsfiles fromprotofiles - Generate interfaces from messages
- Generate enumerations
- Supported interface fields types:
- Scalar types (string, boolean, number, bigint)
- Arrays
- Message type
- Enumeration type
- Generate
phpfiles fromprotofiles - Generate classes from messages
- Generate constants from enumerations