gpt4 book ai didi

gorilla jsonrpc 得到空响应

转载 作者:IT王子 更新时间:2023-10-29 01:59:19 25 4
gpt4 key购买 nike

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

最佳答案

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

type Response struct {
Sum int
Message string
}

关于 gorilla jsonrpc 得到空响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32224644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com