Grpc-go: Is there any guide to get the client IP address and user-agent?

Created on 8 Aug 2018  Â·  3Comments  Â·  Source: grpc/grpc-go

Please let me know if this is a place for asking questions and sorry about that.

What version of gRPC are you using?

I'm using v1.12.0

What version of Go are you using (go version)?

I'm using v1.10.2

What operating system (Linux, Windows, …) and version?

I'm using macOS

What did you do?

If possible, provide a recipe for reproducing the error.
I'm setting up a serials of grpc calls following your official guides which all work fine. but now i'm required to get the client IP address and user-agent. Unfortunately I don't see any pages that introducing how to get it out.

What did you expect to see?

I expect to see a page giving an example how to get the client IP address and user-agent.

What did you see instead?

nothing.

Most helpful comment

To get the IP address you can use the peer package. Use peer.FromContext, and pass in the context you got from the call.

I'm less sure on how to get the user-agent string. Likely you can use the metadata to get it.

All 3 comments

To get the IP address you can use the peer package. Use peer.FromContext, and pass in the context you got from the call.

I'm less sure on how to get the user-agent string. Likely you can use the metadata to get it.

@aaronbee Thank you so much sir!! You saved my day. I haven't tested very much but it looks metadata will be a good solution. Will let you know!!

Thanks @aaronbee for answering the question.
Closing this issue now.

Was this page helpful?
0 / 5 - 0 ratings