mirror of
https://github.com/linka-cloud/grpc.git
synced 2025-04-29 23:27:42 +00:00
proxy: add RegisterServiceDescs
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
parent
8999dedd32
commit
533a0ea43a
@ -40,6 +40,35 @@ func RegisterService(server grpc.ServiceRegistrar, director StreamDirector, serv
|
|||||||
server.RegisterService(fakeDesc, streamer)
|
server.RegisterService(fakeDesc, streamer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RegisterServiceDescs(server grpc.ServiceRegistrar, director StreamDirector, descs ...grpc.ServiceDesc) {
|
||||||
|
streamer := &handler{director}
|
||||||
|
for _, desc := range descs {
|
||||||
|
fakeDesc := &grpc.ServiceDesc{
|
||||||
|
ServiceName: desc.ServiceName,
|
||||||
|
HandlerType: (*interface{})(nil),
|
||||||
|
}
|
||||||
|
for _, desc := range desc.Methods {
|
||||||
|
streamDesc := grpc.StreamDesc{
|
||||||
|
StreamName: desc.MethodName,
|
||||||
|
Handler: streamer.handler,
|
||||||
|
ServerStreams: true,
|
||||||
|
ClientStreams: true,
|
||||||
|
}
|
||||||
|
fakeDesc.Streams = append(fakeDesc.Streams, streamDesc)
|
||||||
|
}
|
||||||
|
for _, desc := range desc.Streams {
|
||||||
|
streamDesc := grpc.StreamDesc{
|
||||||
|
StreamName: desc.StreamName,
|
||||||
|
Handler: streamer.handler,
|
||||||
|
ServerStreams: true,
|
||||||
|
ClientStreams: true,
|
||||||
|
}
|
||||||
|
fakeDesc.Streams = append(fakeDesc.Streams, streamDesc)
|
||||||
|
}
|
||||||
|
server.RegisterService(fakeDesc, streamer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TransparentHandler returns a handler that attempts to proxy all requests that are not registered in the server.
|
// TransparentHandler returns a handler that attempts to proxy all requests that are not registered in the server.
|
||||||
// The indented use here is as a transparent proxy, where the server doesn't know about the services implemented by the
|
// The indented use here is as a transparent proxy, where the server doesn't know about the services implemented by the
|
||||||
// backends. It should be used as a `grpc.UnknownServiceHandler`.
|
// backends. It should be used as a `grpc.UnknownServiceHandler`.
|
||||||
|
@ -216,10 +216,8 @@ func (s *ProxyHappySuite) SetupSuite() {
|
|||||||
grpc.CustomCodec(proxy.Codec()),
|
grpc.CustomCodec(proxy.Codec()),
|
||||||
grpc.UnknownServiceHandler(proxy.TransparentHandler(director)),
|
grpc.UnknownServiceHandler(proxy.TransparentHandler(director)),
|
||||||
)
|
)
|
||||||
// Ping handler is handled as an explicit registration and not as a TransparentHandler.
|
|
||||||
proxy.RegisterService(s.proxy, director,
|
proxy.RegisterServiceDescs(s.proxy, director, pb.TestService_ServiceDesc)
|
||||||
"mwitkow.testproto.TestService",
|
|
||||||
"Ping")
|
|
||||||
|
|
||||||
// Start the serving loops.
|
// Start the serving loops.
|
||||||
s.T().Logf("starting grpc.Server at: %v", s.serverListener.Addr().String())
|
s.T().Logf("starting grpc.Server at: %v", s.serverListener.Addr().String())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user