protoc -I=pb/protos -I=pb/protos/third/github.com pb/protos/custom/*.proto
-I 指定需要import的gogo.proto文件路径, protoc查找过程为 -I后面的路径和import的路径拼接在一起。
- -I=pb/protos
指定proto源文件路径 - -I=pb/protos/third/github.com
指定第三方proto,例如any.proto
protoc --gogofaster_out=./pb/pbs
指定使用插件gogofaster,并且生成到pb/pbs目录下
protoc在执行的时候回到gopath下的bin目录找名为 protoc-gen-gogofaster 可执行文件。
注意:在写命令行调用插件的时候 只需要写protoc-gen- 后面的内容,然后加上 _out
protoc 原本会生成xxx.pb.go,如果在后面有插件的话,那么protoc生成的内容会被传给后面的插件继续丰富文件内容,并且插件可以修改最后输出的文件名。
oneof
import "validator.proto";
message animal{
oneof ani{
option (validator.oneof) = {required:true};
dog d=1;
cat c=2;
}
}
message dog{
string name=1;
}
message cat{
int32 age = 1;
}
validator
message cat{
int32 age = 1[(validator.field)={int_gt:0, int_lt:200}];
}
age必须大于0,小于200