本文整理汇总了Golang中github.com/Terry-Mao/gopush-cluster/rpc.MessageGetResp类的典型用法代码示例。如果您正苦于以下问题:Golang MessageGetResp类的具体用法?Golang MessageGetResp怎么用?Golang MessageGetResp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MessageGetResp类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Get
// Get offline message interface
func (r *MessageRPC) Get(m *myrpc.MessageGetArgs, rw *myrpc.MessageGetResp) error {
if m == nil || m.Key == "" || m.MsgId < 0 {
return myrpc.ErrParam
}
msgs, err := UseStorage.Get(m.Key, m.MsgId)
if err != nil {
glog.Errorf("UseStorage.Get(\"%s\", %d) error(%v)", m.Key, m.MsgId, err)
return err
}
rw.Msgs = msgs
rw.PubMsgs = nil
return nil
}
示例2: Get
// Get offline message interface
func (r *MessageRPC) Get(m *myrpc.MessageGetArgs, rw *myrpc.MessageGetResp) error {
Log.Debug("request data %v", *m)
// Get all of offline messages which larger than MsgID
msgs, err := GetMessages(m.Key, m.MsgID)
if err != nil {
Log.Error("get messages error (%v)", err)
rw.Ret = InternalErr
return nil
}
numMsg := len(msgs)
if len(msgs) == 0 {
rw.Ret = OK
return nil
}
var (
data []string
delMsgs []string
msg = &Message{}
)
// Checkout expired offline messages
for i := 0; i < numMsg; i++ {
if err := json.Unmarshal([]byte(msgs[i]), &msg); err != nil {
Log.Error("internal message:%s error (%v)", msgs[i], err)
rw.Ret = InternalErr
return nil
}
if time.Now().UnixNano() > msg.Expire {
delMsgs = append(delMsgs, msgs[i])
continue
}
data = append(data, msgs[i])
}
// Send to delete message process
if len(delMsgs) != 0 {
r.DelChan <- &DelMessageInfo{Key: m.Key, Msgs: delMsgs}
}
Log.Debug("response data %v", *rw)
rw.Ret = OK
rw.Msgs = data
return nil
}
示例3: GetPrivate
// GetPrivate rpc interface get user private message.
func (r *MessageRPC) GetPrivate(m *myrpc.MessageGetPrivateArgs, rw *myrpc.MessageGetResp) error {
if m == nil || m.Key == "" || m.MsgId < 0 {
return myrpc.ErrParam
}
msgs, err := UseStorage.GetPrivate(m.Key, m.MsgId)
if err != nil {
glog.Errorf("UseStorage.GetPrivate(\"%s\", %d) error(%v)", m.Key, m.MsgId, err)
return err
}
rw.Msgs = msgs
glog.V(1).Infof("UserStorage.GetPrivate(\"%s\", %d) ok", m.Key, m.MsgId)
return nil
}
示例4: GetPrivate
// GetPrivate rpc interface get user private message.
func (r *MessageRPC) GetPrivate(m *myrpc.MessageGetPrivateArgs, rw *myrpc.MessageGetResp) error {
log.Debug("messageRPC.GetPrivate key:\"%s\" mid:\"%d\"", m.Key, m.MsgId)
if m == nil || m.Key == "" || m.MsgId < 0 {
return myrpc.ErrParam
}
msgs, err := UseStorage.GetPrivate(m.Key, m.MsgId)
if err != nil {
log.Error("UseStorage.GetPrivate(\"%s\", %d) error(%v)", m.Key, m.MsgId, err)
return err
}
rw.Msgs = msgs
log.Debug("UserStorage.GetPrivate(\"%s\", %d) ok", m.Key, m.MsgId)
return nil
}
示例5: Get
// Get offline message interface
func (r *MessageRPC) Get(m *myrpc.MessageGetArgs, rw *myrpc.MessageGetResp) error {
Log.Info("request message (mid:%d,pmid:%d,key:%s)", m.MsgID, m.PubMsgID, m.Key)
// Get all of offline messages which larger than MsgID that corresponding to m.Key
msgs, err := UseStorage.Get(m.Key, m.MsgID)
if err != nil {
Log.Error("UseStorage.Get(\"%s\", \"%d\") error(%v)", m.Key, m.MsgID, err)
rw.Ret = myrpc.InternalErr
return nil
}
// Get public offline messages which larger than PubMsgID
pMsgs, err := UseStorage.Get(Conf.PKey, m.PubMsgID)
if err != nil {
Log.Error("UseStorage.Get(\"%s\", \"%d\") error(%v)", Conf.PKey, m.PubMsgID, err)
rw.Ret = myrpc.InternalErr
return nil
}
numMsg := len(msgs)
numPMsg := len(pMsgs)
if numMsg == 0 && numPMsg == 0 {
rw.Ret = myrpc.OK
Log.Info("response message nil, request key(\"%s\") mid(\"%d\") pmid(\"%d\")", m.Key, m.MsgID, m.PubMsgID)
return nil
}
var (
data []string
pData []string
delMsgs []string
delPMsgs []string
msg = &Message{}
tNow = time.Now().UnixNano()
)
// Checkout expired offline messages
for i := 0; i < numMsg; i++ {
if err := json.Unmarshal([]byte(msgs[i]), &msg); err != nil {
Log.Error("internal message:\"%s\" error(%v)", msgs[i], err)
rw.Ret = myrpc.InternalErr
return nil
}
if tNow > msg.Expire {
delMsgs = append(delMsgs, msgs[i])
continue
}
data = append(data, msgs[i])
}
for i := 0; i < numPMsg; i++ {
if err := json.Unmarshal([]byte(pMsgs[i]), &msg); err != nil {
Log.Error("internal message:\"%s\" error(%v)", pMsgs[i], err)
rw.Ret = myrpc.InternalErr
return nil
}
if tNow > msg.Expire {
delPMsgs = append(delPMsgs, pMsgs[i])
continue
}
pData = append(pData, pMsgs[i])
}
// Send to delete message process
if len(delMsgs) != 0 {
Log.Info("delete expire private messages:\"%s\"", msgs)
DelChan <- &DelMessageInfo{Key: m.Key, Msgs: delMsgs}
}
if len(delPMsgs) != 0 {
Log.Info("delete expire public messages:\"%s\"", pMsgs)
DelChan <- &DelMessageInfo{Key: Conf.PKey, Msgs: delPMsgs}
}
rw.Ret = myrpc.OK
rw.Msgs = data
rw.PubMsgs = pData
Log.Info("response private_message(%s) public_message(%s)", data, pData)
return nil
}