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.