是否可以使用 Go net/rpc 检查元数据?

Is it possible to inspect metadata with Go net/rpc?

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 检查样板文件必须在每个函数中进行。

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

将上下文传递给已注册的函数似乎是一个常见的功能请求;然而,根据 https://golang.org/pkg/net/rpc/、"The net/rpc package is frozen and is not accepting new features."