【问题标题】:Is it possible to inspect metadata with Go net/rpc?是否可以使用 Go net/rpc 检查元数据?
【发布时间】:2018-07-20 18:03:56
【问题描述】:

Go 中的 RPC 服务器示例通常看起来像这样(来自https://golang.org/pkg/net/rpc/):

arith := new(Arith)
rpc.Register(arith)
rpc.HandleHTTP()
l, e := net.Listen("tcp", ":1234")
if e != nil {
    log.Fatal("listen error:", e)
}
go http.Serve(l, nil)

在传递给注册函数之前,是否可以检查与连接关联的元数据?我想先根据 ACL 检查客户端 IP、API 密钥和请求的函数。

编辑添加:我意识到可以使用l.RemoteAddr() 从侦听器获取远程地址 - 目前尚不清楚我将如何获取 API 密钥和请求的函数。

进入函数后,我可以获取 API 密钥,但不能获取客户端 IP。在函数内部执行它不太理想,因为 ACL 检查样板必须进入每个函数。

【问题讨论】:

    标签: go rpc


    【解决方案1】:

    遗憾的是,我已经确定如果不分叉 net/rpc 并为其添加上下文功能,这是不可能的。

    将上下文传递给注册函数似乎是一个常见的功能请求;但是,根据https://golang.org/pkg/net/rpc/,“net/rpc 包已冻结,不接受新功能。”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-05
      • 1970-01-01
      • 2015-04-25
      • 1970-01-01
      • 2022-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多