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)
|
return nil, fmt.Errorf("unknown symbol: %v", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search for method in info.
|
// Search for method in info.Methods.
|
||||||
var found bool
|
var found bool
|
||||||
for _, m := range info.Methods {
|
for _, m := range info.Methods {
|
||||||
if m == name[pos+1:] {
|
if m == name[pos+1:] {
|
||||||
@ -222,13 +222,24 @@ func (s *serverReflectionServer) serviceMetadataForSymbol(name string) (interfac
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !found {
|
if found {
|
||||||
return nil, fmt.Errorf("unknown symbol: %v", name)
|
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 info.Metadata, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("unknown symbol: %v", name)
|
||||||
|
}
|
||||||
|
|
||||||
// fileDescEncodingContainingSymbol finds the file descriptor containing the given symbol,
|
// fileDescEncodingContainingSymbol finds the file descriptor containing the given symbol,
|
||||||
// does marshalling on it and returns the marshalled result.
|
// does marshalling on it and returns the marshalled result.
|
||||||
// The given symbol can be a type, a service or a method.
|
// The given symbol can be a type, a service or a method.
|
||||||
|
@ -273,6 +273,7 @@ func testFileContainingSymbol(t *testing.T, stream rpb.ServerReflection_ServerRe
|
|||||||
}{
|
}{
|
||||||
{"grpc.testing.SearchService", fdTestByte},
|
{"grpc.testing.SearchService", fdTestByte},
|
||||||
{"grpc.testing.SearchService.Search", fdTestByte},
|
{"grpc.testing.SearchService.Search", fdTestByte},
|
||||||
|
{"grpc.testing.SearchService.StreamingSearch", fdTestByte},
|
||||||
{"grpc.testing.SearchResponse", fdTestByte},
|
{"grpc.testing.SearchResponse", fdTestByte},
|
||||||
{"grpc.testing.ToBeExtened", fdProto2Byte},
|
{"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
|
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 {
|
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
|
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 is the metadata specified in ServiceDesc when registering service.
|
||||||
Metadata interface{}
|
Metadata interface{}
|
||||||
}
|
}
|
||||||
@ -258,16 +260,18 @@ type ServiceInfo struct {
|
|||||||
func (s *Server) GetServiceInfo() map[string]*ServiceInfo {
|
func (s *Server) GetServiceInfo() map[string]*ServiceInfo {
|
||||||
ret := make(map[string]*ServiceInfo)
|
ret := make(map[string]*ServiceInfo)
|
||||||
for n, srv := range s.m {
|
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 {
|
for m := range srv.md {
|
||||||
methods = append(methods, m)
|
methods = append(methods, m)
|
||||||
}
|
}
|
||||||
for m := range srv.sd {
|
streams := make([]string, 0, len(srv.sd))
|
||||||
methods = append(methods, m)
|
for s := range srv.sd {
|
||||||
|
streams = append(streams, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret[n] = &ServiceInfo{
|
ret[n] = &ServiceInfo{
|
||||||
Methods: methods,
|
Methods: methods,
|
||||||
|
Streams: streams,
|
||||||
Metadata: srv.mdata,
|
Metadata: srv.mdata,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,6 +94,8 @@ func TestGetServiceInfo(t *testing.T) {
|
|||||||
"grpc.testing.EmptyService": &ServiceInfo{
|
"grpc.testing.EmptyService": &ServiceInfo{
|
||||||
Methods: []string{
|
Methods: []string{
|
||||||
"EmptyCall",
|
"EmptyCall",
|
||||||
|
},
|
||||||
|
Streams: []string{
|
||||||
"EmptyStream",
|
"EmptyStream",
|
||||||
},
|
},
|
||||||
Metadata: []int{0, 2, 1, 3},
|
Metadata: []int{0, 2, 1, 3},
|
||||||
|
Reference in New Issue
Block a user