Reputation: 2224
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.
Upvotes: 1
Views: 403
Reputation: 36249
Your Response
fields are unexported. The names should be uppercase:
type Response struct {
Sum int
Message string
}
Upvotes: 3