0

如何将具体类型作为参数传递给 hashcorp go-plugin

我以他们的例子并尝试添加一个参数。

type Foo struct {
    Name string
}

func (g *GoDataRPC) Greet(foo Foo) string {
    var resp string
    err := g.client.Call("Plugin.Greet", &foo, &resp)
    if err != nil {
        panic(err) // Error: gob: local interface type *interface {} can only be decoded from remote interface type; received concrete type Foo
    }
    return resp
}

...

func (s *GoDataRPCServer) Greet(args interface{}, resp *string) error {
    *resp = s.Impl.Greet(args.(Foo))
    return nil
}

我有panic: gob: local interface type *interface {} can only be decoded from remote interface type; received concrete type Foo

我能够通过制作一个界面并将其注册到 gob 来使其工作Foo,这不是我想要的。

func init() {
    gob.Register(new(Foo))
}

编辑: 显示net/rpc完全相同的示例工作,但go-plugin不:

args = &Args{7, 8}
reply = new(Reply)
err = client.Call("Arith.Mul", args, reply)
4

0 回答 0