大猩猩jsonrpc得到空响应

大猩猩jsonrpc得到空响应

问题描述:

Why does my jsonrpc method return an empty response?

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
}

Request:

{"method":"Arith.Add","params":[{"A": 10, "B":2}], "id": 1}

Response:

{
  "result": {},
  "error": null,
  "id": 1
}

However, if I set the type of reply to *string, then this will work fine:

*reply = "Responding with strings works"

Response:

{
  "result": "Responding with strings works",
  "error": null,
  "id": 1
}

I'm using http://www.gorillatoolkit.org/pkg/rpc.

为什么我的jsonrpc方法返回空响应? p>

  类型Args struct {
 A,B int 
} 
 
type响应结构{
 sum int 
消息字符串
} 
 
type Arith int 
 
func(t * Arith)Add(r *  http.Request,args * Args,回复* Response)错误{
 reply.sum = args.A + args.B 
 reply.message =“ Do math” 
 
 //这也不起作用
  
 // *回复=响应{
 //总和:12,
 //消息:“做数学”,
 //} 
 
返回nil 
} 
  code>   pre> 
 
 

请求: p>

  {“ method”:“ Arith.Add”,“ params”:[{“ A”:10,“ B  “:2}],” id“:1} 
  code>  pre> 
 
 

响应: p>

  {
”结果 “:{},
”错误“:null,
” id“:1 
} 
  code>  pre> 
 
 

但是,如果我设置了回复 code>到 * string code>,则可以正常工作: p>

  * reply =“响应字符串有效” 
  代码>  pre> 
 
 

响应: p>

  {
“结果”:“响应字符串有效”,
“错误”:null  ,
“ id”:1 
} 
  code>  pre> 
 
 

我正在使用 http://www.gorillatoolkit.org/pkg/rpc 。 p> div>

Your Response fields are unexported. The names should be uppercase:

type Response struct {
    Sum     int
    Message string
}