I have a GRPC server that exposes its services via reflection. From the Terminal grpcurl
it as
> grpcurl -plaintext localhost:50051 list
grpc.reflection.v1.ServerReflection
grpc.reflection.v1alpha.ServerReflection
... other services
How would I do the same programmatically from a client code? For instance
conn, err := grpc.NewClient(
"localhost:50051",
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
I have a grpc connection above, how do I invoke the list
method? I'm new to Go so appreciate any pointers.
I have a GRPC server that exposes its services via reflection. From the Terminal grpcurl
it as
> grpcurl -plaintext localhost:50051 list
grpc.reflection.v1.ServerReflection
grpc.reflection.v1alpha.ServerReflection
... other services
How would I do the same programmatically from a client code? For instance
conn, err := grpc.NewClient(
"localhost:50051",
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
I have a grpc connection above, how do I invoke the list
method? I'm new to Go so appreciate any pointers.
- This reeks of an X-Y problem to me: Why would you need to list the endpoints? You should have the message types, and a client in the generated code. The main use-case for grpc reflection (and tools like grpcurl) is debugging. – Elias Van Ootegem Commented Feb 16 at 13:30
1 Answer
Reset to default 0try to dial with insecure.NewCredentials() for plaintext communication and then create a reflection client with reflectionpb.NewServerReflectionClient, send a ServerReflectionRequest with the ListServices method using ServerReflectionInfo. The response from the server should contain a list of available services, which you can print. This copies the behavior of grpcurl -plaintext localhost:50051 list but in client code.. Do you need an example code?