最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

go - Programatically invoke GRPC server reflection list call - Stack Overflow

programmeradmin3浏览0评论

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.

Share Improve this question edited Feb 16 at 12:15 Mark Rotteveel 109k227 gold badges156 silver badges220 bronze badges asked Feb 14 at 2:37 hydradonhydradon 1,4362 gold badges24 silver badges57 bronze badges 1
  • 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
Add a comment  | 

1 Answer 1

Reset to default 0

try 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?

发布评论

评论列表(0)

  1. 暂无评论