Please let me know if this is a place for asking questions and sorry about that.
I'm using v1.12.0
go version)?I'm using v1.10.2
I'm using macOS
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.
I expect to see a page giving an example how to get the client IP address and user-agent.
nothing.
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.
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.