I am testing grpc-gateway and trying to figure out the best way to import dependencies in my grpc service. I have the following dir structure:
proto/
api.proto
api2.proto
third_party/
googleapis/
google/
api/
http.proto
annotations.proto
buf.yaml
buf.gen.yaml
buf.yaml config
version: v1beta1
build:
roots:
- third_party/googleapis
- third_party/grpc-gateway
- proto
Two things
googleapi
under proto files intentionally and would like to keep them separate somewhere. I know google recommends keeping everything under proto
folder and just copying dependent files (like google/api/annotations.proto
), but I am not a fan of copying dozens of dependencies into my source code if I can avoid that somehow.My question is, whenever I run buf generate --path=./proto
(please notice path is set as a directory), I get googleapis
pb.go
files copied under proto/googleapis/
folder. I find it very annoying and cannot figure out what is wrong with my setup. If I specify every file directly, everything is fine (e.g. buf generate --path=./proto/api.proto
), no third-party content is copied.
Is there a way to ignore third_party
folders on buf generate
and if not is there a better way to manage grpc dependencies. Copying files into every grpc project directly does make any sense for me.
Ok, figured that out.
Usually, you'll be either reusing protos from your go/src
folder (which has it's downsides due to repo updates) or you copy them into proto/dependency-x folder.
I find buf to take a bit better approach here, but you have to follow proto structuring guidelines which in short are: structure proto files under same root, in different packets
. So, in order to avoid copying I have to have the following structure:
proto/
api/ <- add one more level
api.proto
api2.proto
third_party/
googleapis/
google/
api/
http.proto
annotations.proto
buf.yaml
buf.gen.yaml
and point buffer right into api
folder like this: buf generate --path=./proto/api