package zhub import "strings" // Lock 分布式锁 type Lock struct { Key string // lock Key Value string // lock Value flagChan chan int // } // Rpc RPC 请求结构 type Rpc struct { Ruk string `json:"ruk"` Topic string `json:"topic"` Value string `json:"value"` Ch chan int `json:"-"` //请求返回标记 RpcResult RpcResult `json:"-"` } // RpcRet RPC 返回值接口 type RpcRet interface { GetRuk() string GetRetcode() int GetRetinfo() string GetResult() any } // RpcResult RPC 返回结果 type RpcResult struct { Ruk string `json:"ruk"` Retcode int `json:"retcode"` Retinfo string `json:"retinfo"` Result any `json:"result"` } func (r *RpcResult) GetRuk() string { return r.Ruk } func (r *RpcResult) GetRetcode() int { return r.Retcode } func (r *RpcResult) GetRetinfo() string { return r.Retinfo } func (r *RpcResult) GetResult() any { return r.Result } func (r *RpcResult) Err(err error) RpcResult { r.Retcode = 100 r.Retinfo = err.Error() return *r } func (r Rpc) backTopic() string { return strings.Split(r.Ruk, "::")[0] } func (r Rpc) Err(err error) RpcResult { return RpcResult{ Retcode: 100, Retinfo: err.Error(), } } func (r Rpc) Render(result any) RpcResult { return RpcResult{ Retcode: 0, Result: result, } }