大猩猩jsonrpc得到空洞的回应

时间:2015-08-26 10:50:43

标签: go rpc json-rpc gorilla

为什么我的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
}

我正在使用http://www.gorillatoolkit.org/pkg/rpc

0 个答案:

没有答案