如何从RPC调用返回空字符串?

如何从RPC调用返回空字符串?

问题描述:

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.

我有一个RPC系统,其中用于结果的接口如下: p> \ n

 类型ValReply结构{
 Val字符串
} 
  code>  pre> 
 
 

有时,我的RPC会将reply.Val设置为“” code>(空字符串)。 在这种情况下,reply.Val中的先前值不会被覆盖,从而使客户端使用不正确的结果。 p>

如何获取RPC调用以返回空字符串? p>

我已经在此问题上进行了搜索,但找不到关于在RPC API中不返回空字符串的任何信息。 p> div>

"" (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.