2015-08-26 44 views
1

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

我正在使用http://www.gorillatoolkit.org/pkg/rpc

回答

3

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

type Response struct { 
    Sum  int 
    Message string 
} 
+0

啊谢谢!就是这样! – theRemix