This is a protoc plugin that assembles protocol buffer messages into a single-valid message for defining Pub/Sub schemas.
Run the following command to install protoc-gen-pubsub-schema
.
go install github.com/alpancs/protoc-gen-pubsub-schema@latest
You need to have protoc
installed.
Follow https://grpc.io/docs/protoc-installation for instruction.
To use this plugin, just run protoc
with an option --pubsub-schema_out
.
protoc
will automatically use protoc-gen-pubsub-schema
executable file.
protoc
and protoc-gen-pubsub-schema
must be found in shell's $PATH
.
# generate assembled proto files with proto2 syntax that accept binary encoding
protoc PROTO_FILES --pubsub-schema_out=OUT_DIR
# generate assembled proto files with proto2 syntax that accept JSON encoding
protoc PROTO_FILES --pubsub-schema_out=OUT_DIR --pubsub-schema_opt=encoding=json
# generate assembled proto files with proto3 syntax that accept JSON encoding
protoc PROTO_FILES --pubsub-schema_out=OUT_DIR --pubsub-schema_opt=syntax=proto3 --pubsub-schema_opt=encoding=json
The following example shows how to generate example/user_add_comment.pubsub.proto from example/user_add_comment.proto.
# include go compiled binaries in the $PATH if it hasn't been there yet
export PATH=$PATH:$(go env GOPATH)/bin
# generate example/user_add_comment.pubsub.proto
protoc example/user_add_comment.proto --pubsub-schema_out=.