Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a shared external package for proto files?

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.

like image 407
Nathan Hyland Avatar asked Dec 03 '18 15:12

Nathan Hyland


2 Answers

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

like image 58
Matteo Avatar answered Dec 02 '22 19:12

Matteo


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"
like image 20
Edson Medina Avatar answered Dec 02 '22 20:12

Edson Medina