github.com/Finschia/finschia-sdk@v0.48.1/client/grpc/reflection/reflection.go (about) 1 package reflection 2 3 import ( 4 "context" 5 6 "google.golang.org/grpc/codes" 7 "google.golang.org/grpc/status" 8 9 "github.com/Finschia/finschia-sdk/codec/types" 10 ) 11 12 type reflectionServiceServer struct { 13 interfaceRegistry types.InterfaceRegistry 14 } 15 16 // NewReflectionServiceServer creates a new reflectionServiceServer. 17 func NewReflectionServiceServer(interfaceRegistry types.InterfaceRegistry) ReflectionServiceServer { 18 return &reflectionServiceServer{interfaceRegistry: interfaceRegistry} 19 } 20 21 var _ ReflectionServiceServer = (*reflectionServiceServer)(nil) 22 23 // ListAllInterfaces implements the ListAllInterfaces method of the 24 // ReflectionServiceServer interface. 25 func (r reflectionServiceServer) ListAllInterfaces(_ context.Context, _ *ListAllInterfacesRequest) (*ListAllInterfacesResponse, error) { 26 ifaces := r.interfaceRegistry.ListAllInterfaces() 27 28 return &ListAllInterfacesResponse{InterfaceNames: ifaces}, nil 29 } 30 31 // ListImplementations implements the ListImplementations method of the 32 // ReflectionServiceServer interface. 33 func (r reflectionServiceServer) ListImplementations(_ context.Context, req *ListImplementationsRequest) (*ListImplementationsResponse, error) { 34 if req == nil { 35 return nil, status.Error(codes.InvalidArgument, "empty request") 36 } 37 38 if req.InterfaceName == "" { 39 return nil, status.Error(codes.InvalidArgument, "invalid interface name") 40 } 41 42 impls := r.interfaceRegistry.ListImplementations(req.InterfaceName) 43 44 return &ListImplementationsResponse{ImplementationMessageNames: impls}, nil 45 }