Gorilla jsonrpc得到空回应
问题描述:
为什么我的jsonrpc方法返回空响应?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
}
答
您的Response
字段未导出。名称应该是大写:
type Response struct {
Sum int
Message string
}
啊谢谢!就是这样! – theRemix