I have an RPC system, where the interface used for the result is as follows:
type ValReply struct {
Val string
}
Sometimes, my RPC will set reply.Val to ""
(the empty string). In these cases, the previous value in reply.Val is not overwritten, leaving the incorrect result to be used by the client.
How can I get my RPC call to return an empty string?
I have googled this issue, and I can't find anything about not returning empty strings in the RPC API.
"" (the empty string) is often interpreted by libraries (database, rpc, json) as the default value and just ignored.
To get more control over nil, and "", change the rpc signature to:
type ValReply struct {
Val *string
}
and then the library will distinguish empty, from null etc.