我正在Go中编写protoc插件,它应该为我们的GRPC服务生成文档,并且目前正在努力尝试了解正确的选项顺序。
首先,protobuf是怎样的
syntax = "proto3";
option go_package = "sample";
package sample
import "common/extensions.proto"
message SimpleMessage {
// Id represents the message identifier.
string id = 1;
int64 num = 2;
}
message Response {
int32 code = 1;
}
enum ErrorCodes {
RESERVED = 0;
OK = 200
ERROR = 6000
PANIC = 6001
}
service EchoService {
rpc Echo (SimpleMessage) returns (Response) {
// common.grpc_status is an extension defined somewhere
// these are list of possible return statuses
option (common.grpc_status) = {
status: "OK"
status: "ERROR"
status: "PANIC" // Every status string will must be one of ErrorCodes items
};
option (common.middlewares) = {
middleware: "csrf"
middleware: "session"
}
}
};
如你所见,这里有两个选项。问题是protoc
没有将位置直接绑定到令牌。它将这些信息留在一个特殊的部分,通过使用所谓的"路径"来恢复它。这些路径依赖于订单,而选项是隐藏的,只能使用proto.GetExtension
函数检索,该函数既不会报告选项索引。
我需要此令牌位置信息来报告错误。有没有办法获得期权指数或等价物?
我正在考虑使用独立解析器来检索正确的顺序,但这感觉有点尴尬。希望有更好的方法。