https://github.com/apoprotsky/protoc-gen-tpl
proto-gen-tpl is a protoc plugin for generating files using custom templates
https://github.com/apoprotsky/protoc-gen-tpl
go golang php protobuf protobuf-plugin protocol-buffers typescript
Last synced: 5 months ago
JSON representation
proto-gen-tpl is a protoc plugin for generating files using custom templates
- Host: GitHub
- URL: https://github.com/apoprotsky/protoc-gen-tpl
- Owner: apoprotsky
- License: mit
- Created: 2021-05-09T21:20:43.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-06-22T22:36:22.000Z (almost 4 years ago)
- Last Synced: 2024-06-21T18:56:26.153Z (almost 2 years ago)
- Topics: go, golang, php, protobuf, protobuf-plugin, protocol-buffers, typescript
- Language: Go
- Homepage:
- Size: 99.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# protoc-gen-tpl
[](https://goreportcard.com/report/github.com/apoprotsky/protoc-gen-tpl)
## Overview
`protoc-gen-tpl` is a plugin for protobuf compiler (`protoc`) which allows to generate files using custom templates and rules.
See in [checklist](#checklist) implemented and planned features.
## Prerequisites
You need protobuf compiler. See instructions on [Protocol Buffers site](https://developers.google.com/protocol-buffers).
Install on `Linux` using `apt`
```sh
apt install protobuf-compiler
```
Install on `macOS` using [Homebrew](https://brew.sh)
```sh
brew install protobuf
```
## Installation
Install `protoc-gen-tpl` plugin using [go](https://golang.org)
```
go get github.com/apoprotsky/protoc-gen-tpl
```
## How to use
Example how to generate go code from proto files
```sh
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/*.proto
```
Option `prefix` has [same behaviour](https://developers.google.com/protocol-buffers/docs/reference/go-generated#invocation) as `module=$PREFIX` for go plugin.
Option `lang` designates which languages to use for output files. This option can be specified multiple times.
## Checklist
### Go
- [x] Generate `go` files from `proto` files
- [x] Generate structs types from messages
- [x] Generate struct fields tags
- [x] Generate json tags
- [x] Generate custom tags
- [ ] Generate types from enumerations
- [ ] Generate constants from enumerations
- [ ] Supported struct fields types:
- [x] Scalar types (string, numbers)
- [x] Arrays
- [x] Message type
- [ ] Enumeration type
### Typescript
- [x] Generate `ts` files from `proto` files
- [x] Generate interfaces from messages
- [ ] Generate enumerations
- [ ] Supported interface fields types:
- [x] Scalar types (string, boolean, number, bigint)
- [x] Arrays
- [x] Message type
- [ ] Enumeration type
### PHP
- [x] Generate `php` files from `proto` files
- [x] Generate classes from messages
- [ ] Generate constants from enumerations