doulan2827 2018-07-20 18:03
浏览 70
已采纳

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

Examples of an RPC server in Go often look something like this (from 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)

Is it possible to inspect the metadata associated with the connection before it is passed off to the registered function? I would like to check the client IP, API key, and requested function against an ACL first.

Edit to add: I realize that can get the remote address from the listener with l.RemoteAddr() - it isn't clear how I would get the API key, and requested function.

Once inside the function, I can get the API key, but not the client IP. Doing it inside the function is less than desirable because ACL check boilerplate would have to go in every function.

  • 写回答

1条回答 默认 最新

  • douwu5009 2018-07-23 21:45
    关注

    Regrettably, I have determined that this is not possible without forking net/rpc and adding context functionality to it.

    Passing a context to the registered function appears to be a common feature request; however, per https://golang.org/pkg/net/rpc/, "The net/rpc package is frozen and is not accepting new features."

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助