为了账号安全,请及时绑定邮箱和手机立即绑定

大猩猩 jsonrpc 得到空响应

大猩猩 jsonrpc 得到空响应

Go
一只萌萌小番薯 2021-11-01 16:46:34
为什么我的 jsonrpc 方法返回空响应?type Args struct {  A, B int}type Response struct {  sum int  message string}type Arith intfunc (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。
查看完整描述

1 回答

?
收到一只叮咚

TA贡献1821条经验 获得超4个赞

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


type Response struct {

    Sum     int

    Message string

}


查看完整回答
反对 回复 2021-11-01
  • 1 回答
  • 0 关注
  • 173 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信