I am trying to send a concrete implementation over RPC. The RPC methods expects a interface.
The relevant code snippets are:
In package node
:
type Commander interface {
Action() string
}
type Approach struct {
Position int
}
func (p Approach) Action() string {
return "Approach"
}
func (t *RPCMethod) RPCAction(command Commander, reply *int) error {
// RPC Method
}
In package main
:
import "node"
gob.Register(node.Approach{})
var p = node.Approach{position}
var q node.Commander = p
var reply int
err = client.Call("RPCMethod.RPCAction",&q, &reply)
I have registered the node.Approach with the gob. But on running the main program I am receiving
gob: name not registered for interface: "node.Approach"
Any ideas on what I am doing wrong? Or how to register name?
Yes, you have registered node.Approach
with the gob. But then you pass q
, which is not node.Approach
. Send p
instead, because that has the type you have registered.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With