Add StreamInfo for streaming types

This commit is contained in:
Menghan Li
2016-07-06 11:47:40 -07:00
parent a518fa911d
commit 0ea9f970c0
3 changed files with 28 additions and 12 deletions

View File

@ -228,7 +228,7 @@ func (s *serverReflectionServer) serviceMetadataForSymbol(name string) (interfac
// Search for stream in info.Streams. // Search for stream in info.Streams.
for _, m := range info.Streams { for _, m := range info.Streams {
if m == name[pos+1:] { if m.Name == name[pos+1:] {
found = true found = true
break break
} }

View File

@ -245,12 +245,22 @@ func (s *Server) register(sd *ServiceDesc, ss interface{}) {
s.m[sd.ServiceName] = srv s.m[sd.ServiceName] = srv
} }
// ServiceInfo contains unary rpc names, streaming rpc names and metadata for a service. // StreamInfo contains information about a streaming RPC.
type StreamInfo struct {
// Name is the RPC name only, without the service name or package name.
Name string
// IsClientStream indicates whether the RPC is a client streaming RPC.
IsClientStream bool
// IsServerStream indicates whether the RPC is a server streaming RPC.
IsServerStream bool
}
// ServiceInfo contains unary RPC names, streaming RPC infos and metadata for a service.
type ServiceInfo struct { type ServiceInfo struct {
// Methods are unary rpc names only, without the service name or package name. // Methods are unary RPC names only, without the service name or package name.
Methods []string Methods []string
// Streams are streaming rpc names only, without the service name or package name. // Streams are streaming RPC names and streaming types.
Streams []string Streams []*StreamInfo
// Metadata is the metadata specified in ServiceDesc when registering service. // Metadata is the metadata specified in ServiceDesc when registering service.
Metadata interface{} Metadata interface{}
} }
@ -264,9 +274,13 @@ func (s *Server) GetServiceInfo() map[string]*ServiceInfo {
for m := range srv.md { for m := range srv.md {
methods = append(methods, m) methods = append(methods, m)
} }
streams := make([]string, 0, len(srv.sd)) streams := make([]*StreamInfo, 0, len(srv.sd))
for s := range srv.sd { for s, d := range srv.sd {
streams = append(streams, s) streams = append(streams, &StreamInfo{
Name: s,
IsClientStream: d.ClientStreams,
IsServerStream: d.ServerStreams,
})
} }
ret[n] = &ServiceInfo{ ret[n] = &ServiceInfo{

View File

@ -79,7 +79,7 @@ func TestGetServiceInfo(t *testing.T) {
{ {
StreamName: "EmptyStream", StreamName: "EmptyStream",
Handler: nil, Handler: nil,
ServerStreams: true, ServerStreams: false,
ClientStreams: true, ClientStreams: true,
}, },
}, },
@ -95,9 +95,11 @@ func TestGetServiceInfo(t *testing.T) {
Methods: []string{ Methods: []string{
"EmptyCall", "EmptyCall",
}, },
Streams: []string{ Streams: []*StreamInfo{&StreamInfo{
"EmptyStream", Name: "EmptyStream",
}, IsClientStream: true,
IsServerStream: false,
}},
Metadata: []int{0, 2, 1, 3}, Metadata: []int{0, 2, 1, 3},
}, },
} }