Skip to content

Commit

Permalink
strictly backwards compatible alternative
Browse files Browse the repository at this point in the history
  • Loading branch information
jhump committed Apr 23, 2021
1 parent 77b94ac commit ae6e490
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions reflection/serverreflection.go
Expand Up @@ -54,27 +54,30 @@ 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 {
// ServiceRegistrar acts as a registry of exposed gRPC service. It is also an
// interface provided by a gRPC server (*grpc.Server).
type ServiceRegistrar interface {
grpc.ServiceRegistrar
// GetServiceInfo returns information on the services registered thus far.
GetServiceInfo() map[string]grpc.ServiceInfo
}

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

type serverReflectionServer struct {
rpb.UnimplementedServerReflectionServer
s GRPCServer
s ServiceRegistrar

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 GRPCServer) {
func Register(s *grpc.Server) {
RegisterWithRegistrar(s)
}

// RegisterWithRegistrar registers the server reflection service on the given service registrar.
func RegisterWithRegistrar(s ServiceRegistrar) {
rpb.RegisterServerReflectionServer(s, &serverReflectionServer{
s: s,
})
Expand Down

0 comments on commit ae6e490

Please sign in to comment.