Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

name not registered for interface

Tags:

go

rpc

gob

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?

like image 985
user2128233 Avatar asked Mar 03 '13 05:03

user2128233


1 Answers

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.

like image 183
zzzz Avatar answered Sep 24 '22 18:09

zzzz