Split methods and streams in service info
This commit is contained in:
@ -214,7 +214,7 @@ func (s *serverReflectionServer) serviceMetadataForSymbol(name string) (interfac
|
||||
return nil, fmt.Errorf("unknown symbol: %v", name)
|
||||
}
|
||||
|
||||
// Search for method in info.
|
||||
// Search for method in info.Methods.
|
||||
var found bool
|
||||
for _, m := range info.Methods {
|
||||
if m == name[pos+1:] {
|
||||
@ -222,11 +222,22 @@ func (s *serverReflectionServer) serviceMetadataForSymbol(name string) (interfac
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return nil, fmt.Errorf("unknown symbol: %v", name)
|
||||
if found {
|
||||
return info.Metadata, nil
|
||||
}
|
||||
|
||||
return info.Metadata, nil
|
||||
// Search for stream in info.Streams.
|
||||
for _, m := range info.Streams {
|
||||
if m == name[pos+1:] {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if found {
|
||||
return info.Metadata, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("unknown symbol: %v", name)
|
||||
}
|
||||
|
||||
// fileDescEncodingContainingSymbol finds the file descriptor containing the given symbol,
|
||||
|
@ -273,6 +273,7 @@ func testFileContainingSymbol(t *testing.T, stream rpb.ServerReflection_ServerRe
|
||||
}{
|
||||
{"grpc.testing.SearchService", fdTestByte},
|
||||
{"grpc.testing.SearchService.Search", fdTestByte},
|
||||
{"grpc.testing.SearchService.StreamingSearch", fdTestByte},
|
||||
{"grpc.testing.SearchResponse", fdTestByte},
|
||||
{"grpc.testing.ToBeExtened", fdProto2Byte},
|
||||
} {
|
||||
|
14
server.go
14
server.go
@ -245,10 +245,12 @@ func (s *Server) register(sd *ServiceDesc, ss interface{}) {
|
||||
s.m[sd.ServiceName] = srv
|
||||
}
|
||||
|
||||
// ServiceInfo contains method names and metadata for a service.
|
||||
// ServiceInfo contains unary rpc names, streaming rpc names and metadata for a service.
|
||||
type ServiceInfo struct {
|
||||
// Methods are method names only, without the service name or package name.
|
||||
// Methods are unary rpc names only, without the service name or package name.
|
||||
Methods []string
|
||||
// Streams are streaming rpc names only, without the service name or package name.
|
||||
Streams []string
|
||||
// Metadata is the metadata specified in ServiceDesc when registering service.
|
||||
Metadata interface{}
|
||||
}
|
||||
@ -258,16 +260,18 @@ type ServiceInfo struct {
|
||||
func (s *Server) GetServiceInfo() map[string]*ServiceInfo {
|
||||
ret := make(map[string]*ServiceInfo)
|
||||
for n, srv := range s.m {
|
||||
methods := make([]string, 0, len(srv.md)+len(srv.sd))
|
||||
methods := make([]string, 0, len(srv.md))
|
||||
for m := range srv.md {
|
||||
methods = append(methods, m)
|
||||
}
|
||||
for m := range srv.sd {
|
||||
methods = append(methods, m)
|
||||
streams := make([]string, 0, len(srv.sd))
|
||||
for s := range srv.sd {
|
||||
streams = append(streams, s)
|
||||
}
|
||||
|
||||
ret[n] = &ServiceInfo{
|
||||
Methods: methods,
|
||||
Streams: streams,
|
||||
Metadata: srv.mdata,
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +94,8 @@ func TestGetServiceInfo(t *testing.T) {
|
||||
"grpc.testing.EmptyService": &ServiceInfo{
|
||||
Methods: []string{
|
||||
"EmptyCall",
|
||||
},
|
||||
Streams: []string{
|
||||
"EmptyStream",
|
||||
},
|
||||
Metadata: []int{0, 2, 1, 3},
|
||||
|
Reference in New Issue
Block a user