如何在Golang的Thrift服务器中获取客户端的IP地址

huangapple go评论94阅读模式
英文:

How to get client's IP in a golang thrift server

问题

我正在使用golang编写一个thrift服务,我想了解如何在处理函数的上下文中获取客户端的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.

Thanks, Love.

答案1

得分: 1

我认为你正在使用这个Godoc Thrift库。在你的问题中包含代码片段会很好,比如thrift server的类型、handler的定义等等。

根据Thrift Go 库文档的描述:

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

返回套接字的远程地址。

所以如果你可以访问TSocket,你就可以获取远程地址。

英文:

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.

As per Thrift Go library doc-

> func (p *TSocket) Addr() net.Addr
>
> Returns the remote address of the socket.

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

huangapple
  • 本文由 发表于 2017年7月7日 12:55:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/44962798.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定