您的位置:首页 > 编程语言 > Go语言

go 的 protoc 插件调用逻辑

2016-05-13 16:50 429 查看
要让protoc使用插件,需要做下面事情:

PlacethepluginbinarysomewhereinthePATHandgiveitthename"protoc-gen-NAME"(replacing"NAME"withthenameofyourplugin).

Ifyoutheninvokeprotocwiththeparameter–NAME_out=OUT_DIR(again,replace"NAME"withyourplugin'sname),protocwillinvokeyourplugintogeneratetheoutput,whichwillbeplacedinOUT_DIR.

Placethepluginbinaryanywhere,withanyname,andpassthe–pluginparametertoprotoctodirectittoyourpluginlikeso:

protoc--plugin=protoc-gen-NAME=path/to/mybinary--NAME_out=OUT_DIR

OnWindows,makesuretoincludethe.exesuffix:

protoc--plugin=protoc-gen-NAME=path/to/mybinary.exe--NAME_out=OUT_DIR

参考:https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.compiler.plugin

产生go的grpc代码的插件命令为:

protoc--go_out=plugins=grpc,import_path=mypackage:.*.proto
[/code]
[/code]
这里通过--NAME_out,就能知道是需要找protoc-gen-NAME插件,即protoc-gen-go插件。[/code]
而--go_out=plugins=grpc则会在https://github.com/golang/protobuf这里找到
https://github.com/golang/protobuf/blob/master/protoc-gen-go/grpc/grpc.go做为插件。

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: