Skip to content

Instantly share code, notes, and snippets.

@ruandao
Created July 6, 2018 10:12
Show Gist options
  • Save ruandao/1e4d8f4d6c5d05554b802036a3984ae3 to your computer and use it in GitHub Desktop.
Save ruandao/1e4d8f4d6c5d05554b802036a3984ae3 to your computer and use it in GitHub Desktop.
2018/07/06 18:10:51 call err: gob: type not registered for interface: map[string]interface {} panic: call err: gob: type not registered for interface: map[string]interface {} 确定原因是,map赋值给interface{}字段 也就是说,rpc调用不支持interface{}字段咯
package main
import (
"net/rpc"
"log"
"fmt"
)
func failOnErr(err error, s string) {
if err != nil {
s := fmt.Sprintf("%s: %s", s, err)
log.Print(s)
panic(s)
}
}
type Args struct {
X interface{}
}
type Reply struct {
}
func main() {
conn, err := rpc.Dial("tcp", ":9876")
failOnErr(err, "dail fail")
args := Args{
X:map[string]interface{}{},
}
reply := &Reply{}
err = conn.Call("R.T", args, reply)
failOnErr(err, "call err")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment