gRPC奇怪的编译命令protoc


举个栗子:

protoc -I helloworld/ helloworld/helloworld.proto --go_out=plugins=grpc:helloworld

大神说得没错,读文档就算是全英文,读起来也比你读翻译得一般的中文文档好理解很多

protoc:https://developers.google.com/protocol-buffers/docs/gotutorial

grpc:https://grpc.io/

最近在研究Go实现微服务,protoc与gRPC这里不作介绍,只说一点:这个命令怎么用

首先,protoc是一个编译命令,把protoc把*.protoc文件编译成*.pb.go或者*.pb2.py等等。

protoc -I helloworld/ helloworld/helloworld.proto --go_out=plugins=grpc:helloworld

看一下这条命令,/helloworld 是你要提供的相对位置的相对起点,如果是当前所在目录,那就写 . (一个小数点),helloworld/helloworld.proto是你proto文件所在地,后面的 --go_out=plugins=grpc:helloworld是输出目录,如果要输出到helloworld下的hhh目录里,就写为

 protoc -I helloworld/  helloworld/helloworld.proto --go_out=plugins=grpc:helloworld/hhh

如果proto文件在helloworld目录的mizi里,那么怎么写?

 protoc -I helloworld  helloworld/mizi/helloworld.proto --go_out=plugins=grpc:helloworld/hhh

大家执行后回发现,它把mizi目录也带到hhh里,也就是把目录结构保留下来了,如果我想得到下面的结果呢?很简单,调一下相对起点就好!

helloworld linge$  protoc -I helloworld/mizi  helloworld/mizi/helloworld.proto --go_out=plugins=grpc:helloworld/hhh


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM