Search code examples
jsongorpcjson-rpc

Go json-rpc returns empty respond


I'm writing a client-server interaction using json-rpc protocol, via Go standard library. Server side works fine, but i can't get correct respond, i get empty respond. Respond type is public.

Server side

func (h *Handler) AddUser(request UserAuthRequest, respond *uuid.UUID) error {
    log.Printf("AddUser: request:%+v", request)
    id := uuid.New()
    respond = &id
    log.Printf("%v", respond)  // prints generated ID
    return nil
}

Client side

var x uuid.UUID
err = client.Call(
    "Handler.AddUser",
    &UserAuthRequest{},
    &x,
)
if err != nil {
    log.Fatalf("bad request: %v", err)
}
log.Printf("res: %+v", x)  // prints 00000000-0000-0000-0000-000000000000

How can i get non-empty respond


Solution

  • Well, the solution on quite obvious Instead of reassign pointer respond to &id, i need to change value of *respond. So just change line respond = &id to *respond = id That's all