因此,我正在使用类似于以下的代码,并且无法让 RPC 在 FooHolder 中工作,它包含满足接口的对象。我可能遗漏了一些东西,但看起来它应该可以工作 - 使用反射包它可以正确识别类型但是当函数返回时出现问题......
package main
import (
"log"
"net"
"net/rpc"
"net/rpc/jsonrpc"
"reflect"
)
type FooInterface interface {
DoTheBartman(in *string, out *string) error
DoThis(in *[]string, out *[]string) error
NoProblems(in *int, out *int) error
}
type Foo struct {
wibble string
}
func (f *Foo) DoTheBartman(in *string, out *string) error {
log.Println("do the bartman")
*out = "^^[ " + *in + "]^^"
return nil
}
func (f *Foo) DoThis(in *[]string, out *[]string) error {
log.Println("Doing this")
log.Println("Type in - ", reflect.TypeOf(in))
log.Println("Type *in - ", reflect.TypeOf(*in))
log.Println("Type out - ", reflect.TypeOf(out))
log.Println("Type *out - ", reflect.TypeOf(*out))
*out = append(*in, "Hello")
return nil
}
type FooHolder struct {
TheFoos []FooInterface
}
func (fh *FooHolder) GetFoos(in *[]Foo, out *[]Foo) error {
log.Println("Getting Foos...")
log.Println("Type in - ", reflect.TypeOf(in))
log.Println("Type *in - ", reflect.TypeOf(*in))
log.Println("Type out - ", reflect.TypeOf(out))
log.Println("Type *out - ", reflect.TypeOf(*out))
return nil // This fails but with a nil... what's up with that.
}
喵喔喔
相关分类