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