We have a few projects that depend on shared types to communicate. The teams have decided to use a shared package with those types, and would like to use protocol buffers for this implementation. If it matters, the language is Go, and all of these projects are not public.
How can we use protocol buffer types not defined within our project? I can't seem to find a way to share completely external types amongst applications. Everything I read tends to explain how to use sub-package .proto
files but not types defined by another developer/team in another project within your project.
You can use the protoc
and specify the include path, as example:
protoc -I/usr/local/include -I. \
-I${GOPATH}/src \
-I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--go_out=$DST_DIR \
my-proto.proto
Hope this help
Create a repository for your new package (auto generated from the .proto
files). Ie:
protoc --go_out=$GOPATH/your/git/repo /path/to/your/schema.proto
Make sure you git push
the repo.
Then on the external projects that need to use it, just include:
import "your/git/repo/schema/yourStruct"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With