Skip to content

Commit

Permalink
reflection: accept interface instead of grpc.Server struct in Registe…
Browse files Browse the repository at this point in the history
…r() (#4340)
  • Loading branch information
jhump committed Apr 27, 2021
1 parent 52a707c commit 145f12a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions reflection/serverreflection.go
Expand Up @@ -54,17 +54,27 @@ import (
"google.golang.org/grpc/status"
)

// GRPCServer is the interface provided by a gRPC server. It is implemented by
// *grpc.Server, but could also be implemented by other concrete types. It acts
// as a registry, for accumulating the services exposed by the server.
type GRPCServer interface {
grpc.ServiceRegistrar
GetServiceInfo() map[string]grpc.ServiceInfo
}

var _ GRPCServer = (*grpc.Server)(nil)

type serverReflectionServer struct {
rpb.UnimplementedServerReflectionServer
s *grpc.Server
s GRPCServer

initSymbols sync.Once
serviceNames []string
symbols map[string]*dpb.FileDescriptorProto // map of fully-qualified names to files
}

// Register registers the server reflection service on the given gRPC server.
func Register(s *grpc.Server) {
func Register(s GRPCServer) {
rpb.RegisterServerReflectionServer(s, &serverReflectionServer{
s: s,
})
Expand Down

0 comments on commit 145f12a

Please sign in to comment.