當前位置: 首頁>>代碼示例>>Golang>>正文


Golang rpc.MessageGetResp類代碼示例

本文整理匯總了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
}
開發者ID:nosix-me,項目名稱:gopush-cluster,代碼行數:14,代碼來源:rpc.go

示例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
}
開發者ID:Ehuos,項目名稱:gopush-cluster,代碼行數:49,代碼來源:rpc.go

示例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
}
開發者ID:qmdx,項目名稱:gopush-cluster,代碼行數:14,代碼來源:rpc.go

示例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
}
開發者ID:xuguangtech,項目名稱:gopush-cluster,代碼行數:15,代碼來源:rpc.go

示例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
}
開發者ID:voidException,項目名稱:gopush-cluster,代碼行數:79,代碼來源:rpc.go


注:本文中的github.com/Terry-Mao/gopush-cluster/rpc.MessageGetResp類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。