为什么我的jsonrpc方法返回空响应?
type Args struct {
A, B int
}
type Response struct {
sum int
message string
}
type Arith int
func (t *Arith) Add(r *http.Request, args *Args, reply *Response) error {
reply.sum = args.A + args.B
reply.message = "Do math"
// this does not work either
//*reply = Response{
// sum : 12,
// message : "Do math",
//}
return nil
}
请求:
{"method":"Arith.Add","params":[{"A": 10, "B":2}], "id": 1}
响应:
{
"result": {},
"error": null,
"id": 1
}
但是,如果我将reply
的类型设置为*string
,那么这样可以正常工作:
*reply = "Responding with strings works"
响应:
{
"result": "Responding with strings works",
"error": null,
"id": 1
}