I try to write a kv-raft server code in Go. (refer this article).
However I found there is problem if I want using context.Context
in my RPC call parameter
// Init of my RPC server
kv := new(KVRaft)
rpcs := rpc.NewServer()
rpcs.Register(kv)
....
//My RPC call function
func (kv *KVRaft) Msg(args *context.Context, reply *MsgReply) error {
log.Println("[MSG]", *args)
return nil
}
Code could be compiled but when I trying to run
c, _ := rpc.Dial("tcp", ":1234")
var reply MsgReply{}
c.Call("KVRaft.Msg", someContext, &reply)
It will pop-up error as gob: type not registered for interface: context.emptyCtx
This code works well if I replace *context.Context
to *string
.
I googled it could use gob.Register()
, but I got compile failed on gob.Register(context.Context{})
invalid type for composite literal: "golang.org/x/net/context".Context
Any idea how could I pass context.Context
as gob RPC call parameter?
[update]
I try to use gob.Register(context.Background())
but it will get empty context when receive RPC call.
[update] Currently my repo here, but still ongoing.