如何在Golang节俭服务器中获取客户端的IP

如何在Golang节俭服务器中获取客户端的IP

问题描述:

我正在用golang写一个节俭服务,我想了解如何在处理程序函数上下文中获取客户端的IP地址.

I'm writing a thrift service in golang and I would like to understand how I can get the client's IP address in the handler functions context.

谢谢,爱.

我认为您正在使用此

I think you're using this Godoc Thrift library. It would be good to have code snippets in your question; such as type of thrift server, handler definition, etc.

根据Thrift Go 图书馆文档-

As per Thrift Go library doc-

func(p * TSocket)Addr()net.Addr

func (p *TSocket) Addr() net.Addr

返回套接字的远程地址.

Returns the remote address of the socket.

因此,如果您有权访问 TSocket ,则可以获取远程地址.

So if you have access to TSocket then you can get remote address.