This library defines a buf custom plugin.
This plugin reads in a bunch of proto files, and for the RPC services generates some helpers: behaviour modules and "impl" modules to make calling and testing gRPC methods easier.
This repo is not intended to be used directly, but rather includes an escript. This can be used as part of a shell script:
which protoc-gen-elixir-rpc || PATH="~/.mix/escripts:$PATH" && mix escript.install --force github surgeventures/elixir-rpc-proto-gen-helpersThen you can use the plugin for buf generate. An example buf config file might be:
version: v2
plugins:
- local: protoc-gen-elixir
strategy: all
out: ./lib/generated
opt: plugins=grpc
- local: protoc-gen-elixir-rpc
strategy: all
out: ./lib/generated
opt: plugins=grpcYou can also exclude packages from being generated by adding exclude_packages to the opt field:
version: v2
plugins:
- local: protoc-gen-elixir
strategy: all
out: ./lib/generated
opt: plugins=grpc
- local: protoc-gen-elixir-rpc
strategy: all
out: ./lib/generated
opt:
- plugins=grpc
- exclude_packages=rpc.gift_cards.v1If you want to exclude multiple packages, delimit them with a comma.
Note that protoc-gen-elixir is a separate plugin.
To visualise the metadata structure that is parsed, see buf.example.json.
To generate such a file run buf build --output export.json.
## Testing
This plugin is tested with integration tests which call buf generate.
If you want to run tests, make sure you have buf installed at version 1.40 or greater.
Running tests assumes that certain executables are in your PATH:
PATH="~/.mix/escripts:$PATH" && \
mix escript.install --force hex protobuf 0.7.1 && \
mix escript.build && mix escript.install --force protoc-gen-elixir-rpcEvery time you change the CLI code, you must run mix escript.build && mix escript.install --force protoc-gen-elixir-rpc.
If available in Hex, the package can be installed
by adding rpc_proto_gen_helpers to your list of dependencies in mix.exs:
def deps do
[
{:rpc_proto_gen_helpers, "~> 0.1.0"}
]
endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/rpc_proto_gen_helpers.