我正在尝试做一些逆向工程,试图了解几个 .proto 文件中调用了哪些服务。我的问题是是否有可能在服务器上实现一个服务来处理所有的调用,并为我提供调用了哪个函数和服务的信息。
例子:
协议.proto
syntax = "proto3";
package greating;
message PersonRequest {
string name = 1;
int32 age = 2;
}
message PersonResponse {
string message = 1;
}
service GreatingService {
rpc helloPerson (PersonRequest) returns (PersonResponse);
}
service WarningService {
rpc attentionPerson (PersonRequest) returns (PersonResponse);
}
服务器.js
const packageDefinition = protoLoader.loadSync("greating.proto");
const greatingProto = grpc.loadPackageDefinition(packageDefinition);
var server = new grpc.Server();
server.addService(greatingProto.greating.GreatingService.service, {
helloPerson: function(call, callback) {
let response = `Hello ${call.request.name}! You're ${call.request.age} years old`;
return callback(null, { message: response });
}
});
server.addService(greatingProto.greating.WarningService.service, {
helloPerson: function(call, callback) {
let response = `Attention ${call.request.name}! You're ${call.request.age} years left to live`;
return callback(null, { message: response });
}
});
我想要做的是实现处理两个(所有)调用的第三个函数,并显示调用了哪个服务。像这样的东西:
server.addService("*", {
function(call, callback) {
let response = `The service ${call.service}, function ${call.function} was called.`;
return callback(null, { message: response });
}
});
有没有办法做到这一点?
谢谢你。