【问题标题】:Gorilla jsonrpc getting empty response大猩猩jsonrpc得到空响应
【发布时间】:2015-11-20 09:01:32
【问题描述】:

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

【问题讨论】:

    标签: go rpc json-rpc gorilla


    【解决方案1】:

    您的Response 字段未导出。名称应为大写:

    type Response struct {
        Sum     int
        Message string
    }
    

    【讨论】:

      猜你喜欢
      • 2018-06-08
      • 2014-03-15
      • 2018-09-05
      • 1970-01-01
      • 1970-01-01
      • 2020-08-29
      • 2023-02-20
      • 2014-11-24
      • 2015-03-30
      相关资源
      最近更新 更多